BPF SDK path does not exist

When I was in step 9 of the tutorial named "Solana 101", I was trying to build my first smart contract. But when I use the command as the book says, I got an unexpected error:

$ yarn run solana:build:program                                                                                                       
yarn run v1.22.17
$ cargo build-bpf --manifest-path=contracts/solana/program/Cargo.toml --bpf-out-dir=dist/solana/program
BPF SDK: /Users/alice/.local/share/solana/install/releases/stable-a812f4410ee6195a3b78642f49e07dea69759240/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
    Finished release [optimized] target(s) in 0.28s
cargo-build-bpf child: /Users/alice/.local/share/solana/install/releases/stable-a812f4410ee6195a3b78642f49e07dea69759240/solana-release/bin/sdk/bpf/scripts/strip.sh /Users/alice/Codes/Private/learn-web3-dapp/contracts/solana/program/target/bpfel-unknown-unknown/release/helloworld.so /Users/alice/Codes/Private/learn-web3-dapp/dist/solana/program/helloworld.so
Failed to execute /Users/alice/.local/share/solana/install/releases/stable-a812f4410ee6195a3b78642f49e07dea69759240/solana-release/bin/sdk/bpf/scripts/strip.sh: No such file or directory (os error 2)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

We all know this is not about yarn itself, so I google and google and google...

Most of the solutions are similar, the first solution is cargo build-bpf fails, after I tried the answer which has the most thumbs-ups, I got another error which means not work:

$ yarn run solana:build:program                                                                              
yarn run v1.22.17
$ cargo build-bpf --manifest-path=contracts/solana/program/Cargo.toml --bpf-out-dir=dist/solana/program
BPF SDK path does not exist: /Users/alice/.local/share/solana/install/active_release/bin/sdk/bpf: No such file or directory (os error 2)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.l

After careful comparison, I found my situation may differ from the above question. So I keep searching and I found another question on StackOverflow with the same keyword "BPF SDK path does not exist". In the solution, it told me to up the version of Rust to date and check the version of Solana CLI, so I tried the following:

$ rustup update stable                                                                                       
info: syncing channel updates for 'stable-aarch64-apple-darwin'
-- snip --
  stable-aarch64-apple-darwin updated - rustc 1.60.0 (7737e0b5c 2022-04-04) (from rustc 1.59.0 (9d1b2106e 2022-02-23))

info: checking for self-updates

$ sh -c "$(curl -sSfL https://release.solana.com/v1.10.6/install)"
downloading v1.10.6 installer
  ✨ 1.10.6 initialized

I updated the Rust and reinstall the Solana CLI with an exact version, and after that, I tried the build command again:

$ yarn run solana:build:program                                                                              
yarn run v1.22.17
$ cargo build-bpf --manifest-path=contracts/solana/program/Cargo.toml --bpf-out-dir=dist/solana/program
BPF SDK: /Users/alice/.local/share/solana/install/releases/1.10.6/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: rustup toolchain uninstall bpf
info: uninstalling toolchain 'bpf'
info: toolchain 'bpf' uninstalled
cargo-build-bpf child: rustup toolchain link bpf /Users/alice/.local/share/solana/install/releases/1.10.6/solana-release/bin/sdk/bpf/dependencies/bpf-tools/rust
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
-- snip compile log --
+ rustup toolchain uninstall bpf
info: uninstalling toolchain 'bpf'
info: toolchain 'bpf' uninstalled
+ set -e
+ rustup toolchain link bpf bpf-tools/rust
+ exit 0
cargo-build-bpf child: /Users/alice/.local/share/solana/install/releases/1.10.6/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/llvm-readelf --dyn-symbols /Users/alice/Codes/Private/learn-web3-dapp/dist/solana/program/helloworld.so

To deploy this program:
  $ solana program deploy /Users/alice/Codes/Private/learn-web3-dapp/dist/solana/program/helloworld.so
The program address will default to this keypair (override with --program-id):
  /Users/alice/Codes/Private/learn-web3-dapp/dist/solana/program/helloworld-keypair.json
✨  Done in 23.40s.

Wow! It works! I think maybe the previous version of Solana CLI I installed is somehow broken or not suitable for the Rust version. I'm relieved to finally be able to compile the program.

Last updated