anchor test on Linux CI: 'Failed to get version of local binary: Syntax error' means broken anchor-cli 0.31.0
On GitHub Actions (or any Linux runner) anchor test fails immediately with:
Failed to get version of local binary: /opt/hostedtoolcache/node/22.11.0/x64/lib/node_modules/@coral-xyz/anchor-cli/anchor: 1: Syntax error: "(" unexpectedand nothing else. The same project works on macOS.
The error is not about your code, your Anchor.toml, or your shell. @coral-xyz/anchor-cli 0.31.0 shipped a broken Linux artifact: the file installed at that path is not a valid Linux executable, so /bin/sh tries to interpret it as a script and chokes on the first byte sequence that looks like shell syntax. That is why the message is a shell syntax error rather than anything Anchor-shaped.
Fix, as of 2025: upgrade the CLI.
npm i -g @coral-xyz/anchor-cli@0.31.2If you are pinned to 0.31.0, the workaround is to overwrite the bad file with the official release binary before running tests:
- name: Manually download Anchor binary
run: |
wget https://github.com/coral-xyz/anchor/releases/download/v0.31.0/anchor-0.31.0-x86_64-unknown-linux-gnu
chmod +x anchor-0.31.0-x86_64-unknown-linux-gnu
mv anchor-0.31.0-x86_64-unknown-linux-gnu `which anchor`The generalizable lesson: a Syntax error: "(" unexpected from a tool you never wrote a script for almost always means a binary is being executed as a shell script — check the artifact, not your configuration.
Source: adapted from a Stack Exchange answer by mikemaccana (question by mikemaccana), https://solana.stackexchange.com/questions/21527/anchor-test-shows-failed-to-get-version-of-local-binary-anchor-1-syntax-er — CC BY-SA 4.0