Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change currently active version rust compiler?

I experienced problems when building Solana CLI 1.18.7 with Rust

When I run cargo build-sbf an error appears:

error: package bumpalo v3.15.4 cannot be built because it requires rustc 1.73.0 or newer, while the currently active rustc version is 1.72.0-dev
Either upgrade to rustc 1.73.0 or newer, or use
cargo update -p [email protected] --precise ver
where ver is the latest version of bumpalo supporting rustc 1.72.0-dev

It assumes currently active rustc version 1.72.0-dev, when I run rustup -V

rustup 1.27.0 (bbb9276d2 2024-03-08)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active rustc version is rustc 1.76.0 (07dca489a 2024-02-04)

This is the same when I run rustc -V currently active rustc version is 1.76.0. When I downgrade Solana CLI, error package bumpalo detect rustc active version is 1.68.0.

How could this happen? Then how can I continue building Solana

like image 925
Miumicream Avatar asked May 24 '26 13:05

Miumicream


2 Answers

The repository probably has a rust-toolchain.toml file which pins a compiler version, thus why rustup/rustc/cargo --version reports different active toolchain versions in different directories.

If you have installed rust via rustup (which appears to be the case), you can specify a toolchain override on CLI like so: cargo +<TOOLCHAIN> <COMMAND>, in your case, try cargo +stable build-sbf. Alternatively, there is the RUSTUP_TOOLCHAIN environment variable you can set, which might be more convenient if you are writing a CI script for example.

All this is well documented in rust's official documentation.

like image 132
cyqsimon Avatar answered May 26 '26 17:05

cyqsimon


I just ran into this problem too and was able to fix this with this command:

solana-install init 1.18.12

Explanation I tried the cargo +stable build-sbf command as suggested in comments above and got no result. My guess is that build-sbf is specifically requiring the solana toolchain and thus overrides stable.

If you run rustup show, you should see your default toolchain and another installed toolchain named solana. That's your culprit. Switching to that toolchain (via rustup default solana) and run rust --version, you'll see that's where the old rustc version 1.68 came from.

The command above fixes this by installing the v1.18.x Solana CLI and its associated Rust toolchain.

Hope this works for you too. Good luck!

like image 26
lastoneisbearfood Avatar answered May 26 '26 19:05

lastoneisbearfood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!