Although both the Solana Tool Suite and Anchor have already got good native support for the M1 architecture, there are currently no official binary builds for the new Macs.
In this guide, we will go through all the steps needed to compile and install the tools on your machine natively, without having to set up a cumbersome Rosetta environment.
Install Rust
First, you will need to install the Rust toolchain.
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
rustup component add rustfmt
This should be all what we need.
Install Solana Tool Suite
Before compiling the Solana Tool Suite, you will need coreutils
installed on your computer in case you don’t have it:
brew install coreutils
Now let’s clone the Solana repository. I’m using shallow cloning to speed up things since the entire commit history is not needed.
# grab only the repo state at the v1.9.2 tag
git clone --depth 1 --branch v1.9.2 https://github.com/solana-labs/solana.git
Then, go into the directory and run the cargo-install-all.sh
script.
cd solana
./scripts/cargo-install-all.sh .
echo "export PATH=$PWD/bin:\$PATH" >> ~/.zshrc
This will take a while, but after it is finished, you can verify if the installation is successful with:
solana --version
There used to be an issue with solana-test-validator
on M1 Macs, but the problem has been solved. You can try to spin it up to make sure it works.
Install Anchor
Anchor is the recommended framework for Solana programs.
Note that Anchor uses Yarn v1 to manage Javascript dependencies in your project, so make sure you already have it installed on your computer.
Since there’s no official binary available for the M1 architecture, we’ll also need to build from source:
cargo install --git https://github.com/project-serum/anchor --tag v0.19.0 anchor-cli --locked
Then, you can verify if the installation is successful with:
anchor --version
And that’s it. Have fun building with Solana on your M1 Mac natively!
Also building in Web3? Let's connect via Twitter 👋 @0xMuse
Top comments (1)
This tutorial worked fine for me until I ran into an issue with compiling ring (ring-rs) which has a dependency of hidapi. I would get errors like:
I have no idea how I fixed it but after dozens of tweaks, uninstalls/reinstalls and running anchor build and cargo build-bpf for the 100th time It eventually compiled and I noticed that the following commands were ran automatically during the compilation:
(I assume the bpf-tools directory is solana/bin/sdk/bpf/dependencies/bpf-tools/rust)
Wish I could provide more details but I have no idea what I did to trigger the above behaviour. Hopefully someone who ends up in the same boat finds this comment and it saves them some time.