In Rust, by default, files are placed in $HOME/.cargo
and $HOME/.rustup
. Is there any way to override these defaults?
I am trying to debug an obscure issue and I want to try changing the file locations.
In Rust, by default, files are placed in $HOME/.cargo
and $HOME/.rustup
. Is there any way to override these defaults?
I am trying to debug an obscure issue and I want to try changing the file locations.
This is explained in the documentation:
rustup
allows you to customise your installation by setting the environment variablesCARGO_HOME
andRUSTUP_HOME
before running therustup-init
executable. As mentioned in the Environment Variables section,RUSTUP_HOME
sets the root rustup folder, which is used for storing installed toolchains and configuration options.CARGO_HOME
contains cache files used by cargo.
Don't forget to update the $PATH
or you won't be able to use the binaries. Also, if you want that setup to be permanent, export those variables from your shell configuration (e.g. .bashrc
or .zshrc
):
Note that you will need to ensure these environment variables are always set and that
CARGO_HOME/bin
is in the$PATH
environment variable when using the toolchain.
Before installing Rust, set the environment variables CARGO_HOME
and RUSTUP_HOME
, and make sure they're set when using the toolchain.
Add the below to your shell profile (~/.bashrc
, ~/.zshrc
, etc.):
Environment variables for cargo and rustup
export CARGO_HOME=/path/to/your/custom/location
export RUSTUP_HOME=/path/to/your/custom/location
Install Rust using rustup - this is the recommended method
RUSTUP_HOME=$RUSTUP_HOME CARGO_HOME=$CARGO_HOME bash -c 'curl https://sh.rustup.rs -sSf | sh'
Add Cargo's bin directory to $PATH:
export PATH=$PATH:$CARGO_HOME/bin
Source Cargo's environment
source "$CARGO_HOME/env"
Restart shell
Verify:
rustc --version
cargo --version
This is explained in the documentation:
rustup
allows you to customise your installation by setting the environment variablesCARGO_HOME
andRUSTUP_HOME
before running therustup-init
executable. As mentioned in the Environment Variables section,RUSTUP_HOME
sets the root rustup folder, which is used for storing installed toolchains and configuration options.CARGO_HOME
contains cache files used by cargo.
Don't forget to update the $PATH
or you won't be able to use the binaries. Also, if you want that setup to be permanent, export those variables from your shell configuration (e.g. .bashrc
or .zshrc
):
Note that you will need to ensure these environment variables are always set and that
CARGO_HOME/bin
is in the$PATH
environment variable when using the toolchain.
© 2022 - 2024 — McMap. All rights reserved.
CARGO_HOME
andCARGO_HOME
. Please edit this answer to clarify what new information is provided. – Prevent