rustrust-cargorustup

Rust version problem when running cargo build-bpf


I am trying to run cargo build-bpf on a basic start rust program.

I installed Rust with the curl command curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh.

When I run cargo --version I get cargo 1.75.0 (1d8b05cdd 2023-11-20). When I run rustc --version I get rustc 1.75.0 (82e1608df 2023-12-21).

But in my project directory, when I run cargo build-bpf I get an error saying:

error: package `package` cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.68.0-dev

How is it using version 1.68.0-dev? I tried running rustup update but I still get the 1.68.0-dev error?


Solution

  • I ran solana-install update and it said "Install is up to date".

    Ran cargo build-bpf again and got error:

    error: package `solana-program v1.18.1` cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.68.0-dev
    Either upgrade to rustc 1.72.0 or newer, or use
    cargo update -p solana-program@1.18.1 --precise ver
    where `ver` is the latest version of `solana-program` supporting rustc 1.68.0-dev
    

    To fix it I ran the following: solana-install init 1.18.1 and then when I ran cargo build-bpf again it worked.