How to switch between Rust toolchains?

Palash Nigam picture Palash Nigam · Oct 3, 2019 · Viewed 34.1k times · Source

rustup help toolchain lists the following sub-commands

SUBCOMMANDS:
    list         List installed toolchains
    install      Install or update a given toolchain
    uninstall    Uninstall a toolchain
    link         Create a custom toolchain by symlinking to a directory
    help         Prints this message or the help of the given subcommand(s)

I have the following toolchains installed

stable-x86_64-unknown-linux-gnu (default)
nightly-2019-09-05-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
master

I was trying to solve an issue for rust-clippy so I had to install the master toolchain. Even though stable is set as my default toolchain, my current toolchain is master and I would like to switch back to stable. How do I do it without uninstalling the master toolchain?

Is there no switch subcommand?

Answer

STEEL picture STEEL · Nov 5, 2020

The rustup default stable command works well, but the easiest way is to keep a rust-toolchain file inside your project root folder. This is similar to a .nvm file for a NodeJS project.

rust-toolchain

nightly

or

stable

rust-toolchain