BPF: thread 'main' panicked at 'Failed to install bpf-tools: "Permission denied

Arch Linux
Rustup and everything is up to date

When compiliying a project, I have this:

 cargo build-bpf
BPF SDK: /opt/solana-release/bin/sdk/bpf
thread 'main' panicked at 'Failed to install bpf-tools: "Permission denied (os error 13)"', sdk/cargo-build-bpf/src/main.rs:440:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

How to fix that?

Does it give more information if you set RUST_BACKTRACE=1 as suggested in the error message?

% RUST_BACKTRACE=1 cargo build-bpf     
BPF SDK: /opt/solana-release/bin/sdk/bpf
thread 'main' panicked at 'Failed to install bpf-tools: "Permission denied (os error 13)"', sdk/cargo-build-bpf/src/main.rs:440:6
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/panicking.rs:92:14
   2: core::option::expect_none_failed
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/option.rs:1329:5
   3: cargo_build_bpf::build_bpf_package
   4: cargo_build_bpf::main

It sounds like the script is trying to install bpf-tools globally and your current user doesn't have adequate permissions.

Does the cargo-build-bpf project provide instructions for how to install them yourself? Otherwise, you can probably just run sudo cargo build-bpf to give it adequate permissions, although I'm always wary of running unknown/untrusted programs as root on my development machine.

cargo-bpf is already present in my system

The error message said it couldn't install "bpf-tools", not "cargo-bpf".

The error message mentioned solana, and after searching their issue tracker on GitHub for "bpf-tools" it looks like this issue has already been reported.

The solution is to run cargo build-bpf as root so it can create the appropriate symlink.

doesn't work

sudo cargo build-bpf
error: no override and no default toolchain set

...

and after

rustup install stable
rustup default stable

the error will remain

Try sudo apt install bpf-tools first. Otherwise, look into how to tell Cargo how to use your user $home/.cargo instead of root's.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.