DEV Community

Cover image for Install Solana on M1 Macs, without Rosetta 💡
0xMuse
0xMuse

Posted on

Install Solana on M1 Macs, without Rosetta 💡

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
Enter fullscreen mode Exit fullscreen mode

Rust is installed

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Solana is installed

This will take a while, but after it is finished, you can verify if the installation is successful with:

solana --version
Enter fullscreen mode Exit fullscreen mode

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.

Solana Test Validator is up and running

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
Enter fullscreen mode Exit fullscreen mode

Then, you can verify if the installation is successful with:

anchor --version
Enter fullscreen mode Exit fullscreen mode

Anchor is installed

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)

Collapse
 
hiddengearz profile image
hiddengearz

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:

  • Unsupported target os for hidapi-rs
  • fatal error: 'IOKit/hid/IOHIDManager.h' file not found
  • did not find header 'hid/IOHIDManager.h' in framework 'IOKit' (loaded from '/System/Library/Frameworks')

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:

./bpf-tools/rust/bin/rustc --version
./bpf-tools/rust/bin/rustc --print sysroot
set +e
rustup toolchain uninstall bpf
info: uninstalling toolchain 'bpf'
info: toolchain 'bpf' uninstalled
set -e
rustup toolchain link bpf bpf-tools/rust
Enter fullscreen mode Exit fullscreen mode

(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.