Search code examples
rustrust-cargo

Change default cargo dependency location


In rust, package manager Cargo, by default fetches the dependency packages like futures or tokio and places at

/home/.cargo/bin , > /home/.cargo/git , > /home/manjaro/.rustup/

. Can user configure different path to fetch rust libraries and get linked during cargo build ?


Solution

  • You are looking for the CARGO_HOME environmental variable. https://doc.rust-lang.org/cargo/guide/cargo-home.html

    There is also an option to set the target directory location: CARGO_TARGET_DIR, https://doc.rust-lang.org/cargo/reference/config.html#buildtarget-dir Some people set it to a global target folder to reduce used disk space if they have multiple projects with similar dependencies.