This Gist talks about installing RustLang to a custom directory on Windows (Tested on Windows 10)
Download rustup-init.exe from https://rustup.rs/ to C:\Downloads\Rust
Open Command Prompt / Terminal by executing Win, type "cmd" and press ctrl + shift + enter to open Command Prompt with Administrator Privileges
Set the Environment variables first to set the installation location for Rustup and Cargo by executing:
setx RUSTUP_HOME "<Drive:\path\to\folder\rustup>"
setx CARGO_HOME "<Drive:\path\to\folder\cargo>"Example:
setx RUSTUP_HOME "C:\Program Files\Compiler\Rust\rustup"
setx CARGO_HOME "C:\Program Files\Compiler\Rust\cargo"Note
Make sure that the directory given to setx <variable_name> and set <variable_name> are same, else you WILL run into issues when you ever change the toolchain or update it.
THIS WILL SET THE INSTALLATION LOCATION OF RUSTUP_HOME AND CARGO_HOME AT THE REGISTRY LEVEL WHICH IS RECOMMENDED.
IN FUTURE, IF YOU EVER WISH TO CHANGE THE LOCATION OF RUST INSTALLATION, JUST CHANGE THE PATH FROM ABOVE AND YOU'LL BE GOOD TO GO.
Note
Make sure that the directory given to setx <variable_name> and set <variable_name> are same, else you WILL run into issues when you ever change the toolchain or update it.
Add the Cargo's bin directory to the PATH environment variable so that you can run Rust commands from anywhere. Run the following command:
set PATH=%PATH%;%CARGO_HOME%\binNow run rustup-init.exe to install Rust within the Command Prompt or Terminal
Within the default host triple, you can either select:
x86_64-pc-windows-msvc(default)x86_64-pc-windows-gnu(type manually)
Leaving default will install "Microsoft Visual Studio" along MSVC build tools that are required by Rust.
Depending on your requirements, you can leave the rest as default (which I did).
In Modify Path variables, Press Y to add the Rust installation directory to the PATH variable.
Wait for installation to complete. Once done, close and re-open the Command Prompt.
Now, Execute:
rustup --versionYou should get something like below:
rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.69.0 (84c898d65 2023-04-16)Additionally you can install other toolchain say MSVC if you installed GNU before by executing:
rustup toolchain install stable-x86_64-pc-windows-msvcTo change default toolchain, execute:
rustup default stable-x86_64-pc-windows- `gnu` or `msvc` depending or your requirements- Open Registry Editor by executing:
Win + R - Then type:
regeditand pressEnter - Locate to
Computer\HKEY_CURRENT_USER\Environmentand DELETECARGO_HOMEandRUSTUP_HOME. - Reboot your PC.
You can uninstall Rust by 2 methods:
- One by executing
rustup self uninstallin terminal / Command Prompt. - Or by Uninstalling from Control panel