How to downgrade Rust compiler to a specific version ?

Hi !

There are a couple of pages/stackoverflow questions which mention how to install a specific Rust version which is pretty straightforward using rustup install command

abdelah@abdelah-VirtualBox:~/workspace/linux$ rustup install 1.62.0
info: syncing channel updates for '1.62.0-x86_64-unknown-linux-gnu'
info: latest update on 2022-06-30, rust version 1.62.0 (a8314ef7d 2022-06-27)

However, there is one tiny step also needed to set the default compiler to the newly installed version, for instance if you run the command above and invoke rustc --version you would still get the previously installed default version.

abdelah@abdelah-VirtualBox:~/workspace/linux$ rustc --version
rustc 1.66.1 (90743e729 2023-01-10)

I am pretty new to Rust ( haven’t read the hello world example fully yet to be honest ), but I already like how the commands come intuitively to mind opposed to other popular tools such as git (always scratched my head trying variants of git checkout and git reset to clean a working directory )

So, back to topic. Now we need to set the default compiler version to 1.62.0, for that we just need to execute rustup deault my-preferred-version but first we can get the list of installed versions like this

abdelah@abdelah-VirtualBox:~/workspace/linux$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)

Then set the default version

abdelah@abdelah-VirtualBox:~/workspace/linux$ rustup default 1.62.0-x86_64-unknown-linux-gnu
info: using existing install for '1.62.0-x86_64-unknown-linux-gnu'
info: default toolchain set to '1.62.0-x86_64-unknown-linux-gnu'

  1.62.0-x86_64-unknown-linux-gnu unchanged - rustc 1.62.0 (a8314ef7d 2022-06-27)

Now, let’s do a smoke test on the compiler version

abdelah@abdelah-VirtualBox:~/workspace/linux$ rustc --version
rustc 1.62.0 (a8314ef7d 2022-06-27)

Okay, this works now !

You might be wondering what would be a usecase for using a specific older compiler version, well my answer to this would be this snippet from Rust documentation in the Linux kernel


A particular version of the Rust compiler is required. Newer versions may or may not work because, for the moment, the kernel depends on some unstable
Rust features.

Starting Linux kernel release v6.1, Rust support was introduced and this grabbed my attention as Rust is claimed to be safer and more secure than C/C++. Safety and Security are two words that one would hear everyday if you work at any company producing or contributing to the production of passenger cars.

I wanted to have a look and play around a bit and then to test if my environment is ready to build Rust in the kernel

abdelah@abdelah-VirtualBox:~/workspace/linux$ make LLVM=1 rustavailable
*** Rust compiler 'rustc' is too new. This may or may not work.
***   Your version:     1.66.1
***   Expected version: 1.62.0
Rust is available!

And because I wouldn’t take may or may not work as an answer, I downgraded my compiler version.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: