Took me a while to figure this out. Posted here to share just in case anybody else in the world is trying to install Rust on an external USB device, for example, to get around build with Rust resulting in running out of disk space on a live Linux USB running on a temporary file system. See Is there a way to [disable] caching crates?.
I have been trying to build Roll your own JavaScript runtime for a while now. My previous attempts resulted in an error due to the disk space being filled by cargo writing downloaded crates to $HOME/.cargo. I start out with around only 1 GB on the live Linux USB temporary file system. I have access to a few external USB devices ranging between 64 GB and 128 GB capacity, so that's not the issue.
This is what worked for me. Making use of CARGO_HOME and RUST_HOME environment variables, along with naming the directories accordingly on the external USB device.
cd /media/user/1234
mkdir rust
wget https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init > rustup-init
chmod +x rustup-init.1
CARGO_HOME=$PWD/rust/.cargo RUSTUP_HOME=$PWD/rust/.rustup ./rustup-init.1 --profile minimal --default-toolchain nightly
. "/media/user/1234/rust/.cargo/env"
CARGO_HOME=$PWD/rust/.cargo RUSTUP_HOME=$PWD/rust/.rustup cargo --version
cargo 1.85.0-nightly (c86f4b3a1 2024-12-24)
CARGO_HOME=$PWD/rust/.cargo RUSTUP_HOME=$PWD/rust/.rustup cargo init --bin runjs
cd runjs
CARGO_HOME=../rust/.cargo RUSTUP_HOME=../rust/.rustup cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.59s
Running `target/debug/runjs`
Hello, world!
CARGO_HOME=../rust/.cargo RUSTUP_HOME=../rust/.rustup cargo add deno_core
Updating crates.io index
Adding deno_core v0.327.0 to dependencies
# ...
CARGO_HOME=../rust/.cargo RUSTUP_HOME=../rust/.rustup cargo add tokio --features=full
Updating crates.io index
Adding tokio v1.42.0 to dependencies
# ...
CARGO_HOME=../rust/.cargo RUSTUP_HOME=../rust/.rustup cargo run
Compiling runjs v0.1.0 (/media/user/1234/runjs)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 22m 09s
Running `target/debug/runjs`
Hello, world!