I’m trying to compile a Solana smart contract using the Anchor framework, but I keep getting a compiler version error.
When I run the build command, I get this error message:
error: package `solana-program v1.18.11` cannot be built because it requires rustc 1.75.0 or newer, while the currently active rustc version is 1.72.0-dev
Either upgrade to rustc 1.75.0 or newer, or use
cargo update -p solana-program@1.18.11 --precise ver
where `ver` is the latest version of `solana-program` supporting rustc 1.72.0-dev
But when I check my Rust version, it shows:
rustc --version
rustc 1.77.0 (aedd173a2 2024-03-17)
And my rustup version is:
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.77.0 (aedd173a2 2024-03-17)`
I’ve already run rustup update
to make sure everything is current. My project directory doesn’t have a rust-toolchain.toml file either.
How can I fix this version mismatch? Any help would be appreciated!
That’s weird! Are you using Docker containers or VSCode dev containers? They sometimes have their own Rust installation that overrides your system one.
Try running which rustc
and whereis rustc
- might show if you’ve got multiple Rust installations fighting each other.
The error mentions 1.72.0-dev
which is odd. Dev versions usually mean a custom build. Did you install Rust through your package manager (apt or brew) instead of rustup? That’d explain the version mismatch.
What does cargo --version
show? Sometimes cargo gets tied to a different Rust version than rustc.
What’s your setup? Linux, Mac, or Windows? And how’d you install Anchor - through cargo or another method?
yea it might have its own toolchain set up. try anchor --version
to see which rust version it needs. sometimes it just doesnt follow the system one, might need to change it in the settings or project dir.
This happens when Anchor uses a different Rust toolchain than your system default. Your global rustc might be 1.77.0, but Anchor’s probably running an older version internally. Run rustup show
in your project directory to see which toolchain is actually compiling. If they don’t match, force Anchor to use your current toolchain with rustup override set stable
in your project root. Also check for any .cargo/config.toml
files that might be specifying an older toolchain. I had this exact issue last month and the override command fixed it instantly.