Skip to content

Instantly share code, notes, and snippets.

@lorisleiva
Last active November 20, 2024 05:44
Show Gist options
  • Save lorisleiva/41ef16a92af68a205a8eea6703d8e6d5 to your computer and use it in GitHub Desktop.
Save lorisleiva/41ef16a92af68a205a8eea6703d8e6d5 to your computer and use it in GitHub Desktop.
Install and use Solana CLI in an Apple M1 before v1.9

Install Solana on Apple M1

Unfortunately, at the time of writing, the Solana installer script above will not work on Apple M1 computers.

The installation will be successful and you’ll be able to call solana commands but other Solana binaries such as solana-test-validator will throw various errors since it’s expecting dependencies to be located elsewhere. If you’ve already installed it that way, no worries, simply run rm -rf ~/.local/share/solana to uninstall Solana.

I’ll be sure to update this article if/when this will work out-of-the-box for M1 computers.

In the meantime, we’ve got a little workaround to go through. We need to clone the Solana repository and compile the binary from the source code. Don’t worry, the installation process is still super simple, it just takes a bit longer due to the compilation time. Here are the steps.

# Go to your dev folder (for me it’s “~/Code”).
cd ~/Code

# Clone the Solana repository and cd into it.
git clone https://github.com/solana-labs/solana.git
cd solana

# Checkout the latest stable branch.
git checkout v1.8.2

# Run the installation script (it takes a while).
./scripts/cargo-install-all.sh .

At the end of the script, it should provide you with a line to copy/paste in your shell configuration to update your PATH accordingly. Open your ~/.zshrc file — or ~/.bashrc or ~/.profile or whatever file you use — and paste that line in there. In my case that was:

export PATH="$HOME/Code/solana/bin:$PATH"

To check that Solana is properly installed, you may run the following commands.

# Check the solana binary is available.
solana --version

# Check you can run a local validator (Run Ctrl+C to exit).
# Notice the special flag. We’ll explain that in a minute.
# Note this creates a "test-ledger" folder in your current directory.
solana-test-validator --no-bpf-jit

If you're having more troubles along the way, Note that Buildspace also has a detailed guide on how to install Solana for Apple M1 computer that they keep up-to-date.

Run a local ledger on Apple M1

There's one little quirk here for Apple M1 users. By default, the local ledger uses something called "BPF just-in-time" which is not compatible with Apple M1 computers. Therefore, we need to add the --no-bpf-jit flag to make it work.

solana-test-validator --no-bpf-jit

Note that this issue should be resolved soon as Solana has already worked on a fix that will automatically detect if a machine supports BPF just-in-time.

Anchor test and localnet on Apple M1

If you're an M1 user, then I'm afraid the anchor test and anchor localnet commands will not work for you just yet.

This is because both of them are calling solana-test-validator without the --no-bpf-jit flag which is necessary for a local ledger to work on an M1 computer. That being said, when this --no-bpf-jit flag issue will be fixed, M1 users should be able to fully enjoy these two anchor commands.

In the meantime, instead of anchor test, you'll need to run:

# Start and reset your local ledger.
solana-test-validator --reset --no-bpf-jit

# Then, on a different terminal session
# Run anchor test without the local ledger.
anchor test --skip-local-validator

And instead of anchor localnet, you'll need to run:

# Start and reset your local ledger.
solana-test-validator --reset --no-bpf-jit

# Then, on a different terminal session
# Build and deploy your program.
anchor build
anchor deploy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment