94

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?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Palash Nigam
  • 1,653
  • 3
  • 14
  • 26
  • AFAIK, there is no "current" toolchain unless you set environment variables. You're either running it like `cargo +nightly clippy` or you're using the default toolchain. – PitaJ Oct 03 '19 at 20:44
  • @PitaJ, running `rustup default` will tell you the default toolchain cargo will use by default unless specified otherwise in a `.toml` config file. – Optimistic Peach Oct 04 '19 at 02:02

4 Answers4

122

Of course the rustup default stable command works well, but the easiest way is to keep a rust-toolchain file inside your project root folder. Similar to how you'd keep a .nvm file for a Node.js project.

Please note that if you use rust-toolchain.toml instead of just rust-toolchain you will need to add needed sections similar to JSON ref and hence I prefer just the simple rust-toolchain file which doesn't need any sections similar to Node.js's .nvm file.

rust-toolchain

nightly

screenshot of IDE with rust-toolchain file

or

stable
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
STEEL
  • 8,955
  • 9
  • 67
  • 89
62

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.

Jason Orendorff
  • 42,793
  • 6
  • 62
  • 96
Francis Gagné
  • 60,274
  • 7
  • 180
  • 155
  • 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 Nov 29 '19 at 03:52
  • 3
    I found the answer: https://github.com/rust-lang/rustup#toolchain-override-shorthand. In the above scenario, I can do `cargo +stable clippy` – James Ray Nov 29 '19 at 04:01
  • Is there any minimal toolchain? I'm only interested in running a few commands such as `cargo generate-lockfile` and `cargo tree` – n1nsa1d00 Jul 05 '21 at 15:56
58

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

rustup override set nightly

or:

rustup override set stable
Rob123
  • 895
  • 6
  • 10
12

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.

Haris Muzaffar
  • 404
  • 6
  • 17