How to switch Rust versions

Rust
Sponsored

Find out which version of Rust is currently in use and how to install and use different versions of Rust.

This article will help you to match Rust versions with your teammates or authors of technical books, and to switch between Rust versions so that your tools work properly.

Find out the current version

C:hogehoge>rustc -V
rustc 1.69.0 (84c898d65 2023-04-16)

With the above command, the current version of Rust can be checked.

The output shows that the current version is 1.69.

Install the version of Rust you want

C:hogehoge>rustup toolchain add 1.68

The above command installs the Rust toolchain of version 1.68.

Confirmation that the version has been installed

C:hogehoge>rustup toolchain list
stable-x86_64-pc-windows-msvc (default)
nightly-2020-01-02-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc
1.68-x86_64-pc-windows-msvc

The above command retrieves a list of installed toolchains.

The bottom line of the output shows that version 1.68 of the toolchain has been installed.

Switching the default toolchain

C:hogehoge>rustup toolchain list
stable-x86_64-pc-windows-msvc (default)
nightly-2020-01-02-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc
1.68-x86_64-pc-windows-msvc

If you look at the top line of the previous output, you will see (default) at the end.

This indicates that there are currently four toolchains installed,

  1. stable
  2. nightly-2020
  3. nightly-x86
  4. 1.68

but the one used for development is "stable" (equivalent to version 1.69 in this case).

Therefore, to use the installed version 1.68, this (default) needs to be changed.

C:hogehoge>rustup default 1.68-x86_64-pc-windows-msvc

The above command changes (default) to 1.68 and the display switches as in

C:hogehoge>rustup toolchain list
stable-x86_64-pc-windows-msvc
nightly-2020-01-02-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc
1.68-x86_64-pc-windows-msvc (default)

You can also check the Rust version directly in the first command to see that the version change has been completed.

C:hogehoge>rustc -V
rustc 1.68.2 (9eb3afe9e 2023-03-27)

Install development targets and tools (if necessary)

When you install a new version of Rust, the corresponding development targets and tools are empty, with nothing installed.

Therefore, install them if necessary.

The following is an example of installing thumbv6m-none-eabi as a development target and elf2uf2-rs as a writing tool for embedded development.

C:hogehoge>rustup target add thumbv6m-none-eabi
C:hogehoge>cargo install elf2uf2-rs -–locked

Comments