To install rustup in different directory (i.e. /opt):
- install rustup in custom directory pointed to by RUSTUP_HOME envvar:
curl https://sh.rustup.rs -sSf | sudo RUSTUP_HOME=/opt/rustup sh -s -- -y
- select default tool chain
sudo RUSTUP_HOME=/opt/rustup rustup default stable
- fix
$HOME/.cargo
permissions afterrustup
installation (it ends up being owned as root)
sudo chown -R <username> .cargo/
- (optional,used by racer) add rust source
sudo RUSTUP_HOME=/opt/rustup rustup component add rust-src
- set up rust-specific env variables
export RUSTUP_HOME=/opt/rustup
export PATH=$HOME/.cargo/bin:$PATH
export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"
- add
RUSTUP_HOME
toDefaults
env_keep
list in/etc/sudoers
to retain this variable forsudo
commands (i.e. updating rustup/rust toolchains)