Ready, Set, Solana! Getting Your M1 Mac Ready for Web3 dev with Solana and Rust
Getting errors trying to develop with Solana on an M1 Mac? Here’s how to set up your M1 development environment.
Getting errors trying to develop with Solana on an M1 Mac? Here’s how to set up your M1 development environment.
You’re ready to get going on blockchain. You’ve done your research (or maybe just went with something which looked interesting) and selected Solana to do your learning on.
Super cool! Solana is an amazing blockchain with a lot to recommend it. It’s blazingly fast, boasting one of the highest Transactions Per Second (TPS) at the time of writing. It’s written in Rust which is an elegant, beautiful and memory safe language.
You’ve made a great choice.
At the time of writing, Solana and M1 chips don’t play nicely together. I kept finding weird and annoying errors any time I tried to test my code. Here’s how I set up my Mac.
Here’s the error I got trying to run solana-test-validator
and solana-test-validator --no-bpf-jit
zsh: illegal hardware instruction solana-test-validator
Here’s how to fix it.
Rosetta 2 is the interpretation layer for interpreting x86 instructions into ARM instructions. The good news is that Apple has done an excellent job with Rosetta 2. You’ll barely even notice you’re using it.
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
For the rest of this tutorial use your Rosetta Terminal
Not everyone I came across online had this issue, but I certainly did. I had Homebrew installed on my M1 already, but I had to install it in a different location.
Here’s the error I got:Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!To rerun under ARM use:arch -arm64 brew install …To install under x86_64, install Homebrew into /usr/local.
Here’s the solution:
cd /usr/local/opt
git clone https://github.com/Homebrew/brew
export PATH=/usr/local/opt/brew/bin:$PATH
brew update
brew install autoconf
Awesome work! Now we’re ready for The Rust Programming Language.
We start by getting RustLang ready to go on our machine under our Rosetta terminal.
Big shout out to Nicholas Garfield for his webpage here. The next few steps came from that site.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
arch -x86_64 brew install coreutils openssl@1.1
(you can update this for later versions if you like)nano ~/.cargo/config
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
[target.aarch64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
Save the file and let’s get into Solana
Here comes the exciting moment we’ve been working towards. Getting Solana working effectively on our M1 Macs.
mkdir ~/Learning
cd ~/Learning
git clone https://github.com/solana-labs/solana.git
cd solana
cargo build
./scripts/cargo-install-all.sh .
export PATH=$PWD/bin:$PATH
Phew. That part probably took you a solid 30 minutes of install time (or maybe it’s a couple of years later and it only took 5 mins. I’m jealous :P )
This is the moment of truth. Did our steps work?
solana
solana-test-validator
If it’s working, you’ll get the following:
Whew. What a relief!
If you’re looking for some learning recommendations, I’d really recommend buildspace. Their courses are fun, interactive, useful and above all insightful.
Specifically for Solana I’d recommend Build a Web3 app on Solana with React and Rust. It’s a brilliant course which walks you through the basics, and by the end you’ll have deployed your first thing on a blockchain (Solana). Plus it’s an easy introduction to Rust and React.
If you found this content helpful, I’d love it if you could connect, clap and share the article. It means a lot ❤