Force `rustup` to install "override" toolchain

There is a rust-toolchain file in my project. The correct version only gets installed on first cargo (or, I guess, rustc) call. But how can I install it explicitly and switch to it, so my next rustup add call will install target on it?

I need something like

rustup toolchain --install-from-toolchain-file
rustup add my_target # target goes to this toolchain

Running any rustup command (even rustup show) inside the folder with the rust-toolchain file will cause it to install the override toolchain if it's not already installed. So you can do this:

cd path/to/my/project/
rustup target add my_target # install the toolchain and add `my_target` to it

You can also switch to a rust-toolchain.toml file and specify one or more targets:

[toolchain]
channel = "nightly-2020-07-10"
targets = [ "my_target" ]

Then just run cargo build (or any other cargo/rustc/rustup command) and it will automatically ensure the toolchain and target are both installed first.

1 Like

Indeed, it worked!
Thank you

@mbrubeck why doesn't rustup add do so btw?
It was kinda strange to call rustup show before rustup add just to install the right toolchain version. Do I probably misuse it?

Thank you.

rustup add is not a valid rustup command. Did you try rustup target add as suggested above?

1 Like

Oops, I think I got the problem: I ran it in the wrong dir. Thank you again

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.