How to switch between Rust toolchains?

28,829

Solution 1

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

Solution 2

Use rustup default <toolchain> to change the default toolchain. You can use the full name (e.g. rustup default stable-x86_64-unknown-linux-gnu) or a short alias (e.g. rustup default stable).

rustup also has methods to override the default in a more scoped manner. See Overrides in the rustup book.

Solution 3

To toggle between nightly and stable configurations in your repo use:

rustup override set nightly

or:

rustup override set stable

Solution 4

rustup default stable should work. This will set stable as the default toolchain globally.

To set stable as the default toolchain for just one directory/ project, use rustup override set stable command instead. To unset it, use rustup override unset.

Share:
28,829
Palash Nigam
Author by

Palash Nigam

Interested programming langauges and distributed systems

Updated on July 08, 2022

Comments

  • Palash Nigam
    Palash Nigam 11 months

    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?

  • James Ray
    James Ray over 3 years
    What if I just want to use switch toolchains temporarily, e.g. also to use cargo clippy, when my default toolchain is nightly?
  • James Ray
    James Ray over 3 years
    I found the answer: github.com/rust-lang/rustup#toolchain-override-shorthand. In the above scenario, I can do cargo +stable clippy
  • Dylan Kerler
    Dylan Kerler over 2 years
    This seems like the more conventional/robust approach so upvoted.
  • n1nsa1d00
    n1nsa1d00 almost 2 years
    Is there any minimal toolchain? I'm only interested in running a few commands such as cargo generate-lockfile and cargo tree