back to homeexplore more short publications
2023-09-30 #short-publication

How to fix solana program build error: requires newer rustc

When you make a build of your Solana program with cargo build-sbf or cargo build-bpf or anchor build it fails with an error that suggests that you have old rustc than required.

$ cargo build-sbf
error: package `solana-program v1.16.14` cannot be built because it requires rustc 1.68.0 or newer, while the currently active rustc version is 1.62.0-dev

It is confusing, especially if you are a Rust developer and uses one of the latest version of rustc.

rustc -V
rustc 1.72.0 (5680fa18f 2023-08-23)

By the way, if you are using build-bpf, it is deprecated, and it is better to switch to build-sbf. Here and after I continue to use build-sbf version and the same applies to build-bpf command.

What's the problem

When you use cargo build-sbf it uses rustc installed with Solana tools.

How to fix

To fix the error, you need to get the latest version or newer enough for your program dependencies of Solana tools. Run the following command to upgrade:

$ solana-install init 1.16.15

You may want to replace "1.16.15" with the latest available version or required version (see the build error message you got).

In case if you do not have solana-install CLI utility you can install it on MacOS & Linux with the command:

$ sh -c "$(curl -sSfL https://release.solana.com/v1.16.15/install)"

or on Windows with the command:

$ cmd /c "curl https://release.solana.com/v1.16.15/solana-install-init-x86_64-pc-windows-msvc.exe --output C:\solana-install-tmp\solana-install-init.exe --create-dirs"