Skip to content

Instantly share code, notes, and snippets.

@pixincreate
Last active May 21, 2023 10:02
Show Gist options
  • Select an option

  • Save pixincreate/4913175908a94270a655edb9fc01cf1a to your computer and use it in GitHub Desktop.

Select an option

Save pixincreate/4913175908a94270a655edb9fc01cf1a to your computer and use it in GitHub Desktop.
This Gist deals with the procedure to install Rust onto a custom or other location isntead of `%USERPROFILE%\.cargo`

Rustup up!

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

Setting Variables

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.

DISCLAIMER

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%\bin

Installation

Now 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 --version

You 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-msvc

To change default toolchain, execute:

rustup default stable-x86_64-pc-windows- `gnu` or `msvc` depending or your requirements

Reverting Installation location

  1. Open Registry Editor by executing: Win + R
  2. Then type: regedit and press Enter
  3. Locate to Computer\HKEY_CURRENT_USER\Environment and DELETE CARGO_HOME and RUSTUP_HOME.
  4. Reboot your PC.

Uninstall Rust (Rustup down!)

You can uninstall Rust by 2 methods:

  • One by executing rustup self uninstall in terminal / Command Prompt.
  • Or by Uninstalling from Control panel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment