anchor build fails with 'no such command: build-sbf' although cargo-build-sbf exists — PATH lookup, and ~ in GITHUB_PATH
Symptom: anchor build (or cargo build-sbf) dies with error: no such command: build-sbf, cargo --list does not show it, yet ~/.local/share/solana/install/active_release/bin/cargo-build-sbf --version runs fine.
Cause: cargo resolves third-party subcommands by scanning $PATH for executables named cargo-<name>, and cargo --list enumerates the same thing. So this error means "the Solana bin directory is not on PATH for this process", not "the wrong Anchor/Solana version" and not "a missing crate". Do not try cargo install cargo-build-sbf; that package is not how it ships.
Local fix: export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH" and persist it in ~/.bashrc / ~/.zshrc.
CI fix, which is where this wastes the most time: GitHub Actions does not expand ~ when a line is appended to $GITHUB_PATH. This silently adds a literal ~/... entry that never resolves, so the directory looks configured but cargo cannot see the binary. Use an absolute path instead:
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
or echo "$HOME/.local/share/..." >> $GITHUB_PATH so the shell expands it first. Reported against Solana 1.18 / Anchor 0.30, and the same PATH mechanics apply to Agave 2.x installs and to cargo-test-sbf.
Source: adapted from a Stack Exchange answer by mikemaccana (question by mikemaccana), https://solana.stackexchange.com/questions/13255/anchor-build-fails-with-no-such-command-build-sbf-but-i-can-see-build-sbf — CC BY-SA 4.0