How to install Solana dev tools on an M1 Mac
Nicholas Garfield
Posted on October 1, 2021
If you're just getting started with Solana development on a new M1 Mac, you might be pulling your hair out right now. Everything was going great as you followed along with Solana's official install guides and ran the solana
CLI command for the first time... but as soon as you tried to spin up a validator using the solana-test-validator
command, you ran into this error message:
dyld: Library not loaded: /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib
Referenced from: /Users/123/.local/share/solana/install/active_release/bin/solana-test-validator
Reason: image not found
zsh: abort solana-test-validator
Maybe you read the error message, got clever and installed OpenSSL… only to run into a different error message:
Ledger location: test-ledger
Log: test-ledger/validator.log
⠁
zsh: illegal hardware instruction solana-test-validator
🧐😕
The problem here is that the Solana dev tools were written for Intel-based x86 chips while the new M1 Macs use an ARM-based architecture. The solution here isn't to sell your shiny new Macbook or pull out an old laptop. Luckily we can use a handy tool called Rosetta to re-compile Solana from the source code in a way that will run on Apple silicon.
1. Start fresh
If you've already tried to set up your environment following Solana's guides, the first thing to do is uninstall everything and start over from scratch.
Begin by locating the Terminal app in Finder, and use the ⌘I
keystroke to open Finder's Inspector window. Make sure the Open using Rosetta option is disabled and restart your Terminal.
Now we can go ahead and cleanly uninstall everything. Let's first uninstall Solana:
rm -rf /Users/USERNAME/.local/share/solana/
And then uninstall Rust:
rustup self uninstall
2. Set up Rosetta
Once you've uninstalled Solana and Rust, your local dev environment will be in a clean state to start over. Let's begin this time by first installing Rosetta:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
Now navigate back to your Finder window and create a duplicate copy of the Terminal application.
We're going to create two versions of Terminal: one that uses Rosetta and one that doesn't. I recommend naming the duplicate Terminal instance to Terminal Rosetta so it's always clear which version you're using.
To enable Rosetta in the Terminal Rosetta version, use the ⌘I
keystroke again to pull up Finder's Inspector window and make sure the Open using Rosetta option is enabled.
From here on out, we're only going to use the Terminal Rosetta app, so I recommend either closing or minimizing your existing Terminal windows to avoid getting them mixed up. Go ahead an open a Terminal Rosetta window for the next section.
3. Install dependencies
Let's dive in and install all the dependencies Solana will need to get running. In a Terminal Rosetta shell, run the following command to install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Next, let's install Homebrew. Note our command starts with the arch -x86_64
prefix. This tells Rosetta to execute the following command using the x86 instruction set.
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Let's also install Coreutils and OpenSSL:
arch -x86_64 brew install coreutils openssl@1.1
Now we need to set up a config file so Cargo knows how to compile Rust code for our machine. Create a new file at ~/.cargo/config
and paste in these build configs:
[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",
]
4. Install and build Solana
Navigate to a stable directory where you can save the Solana source code. For example, I use an umbrella folder for all my projects at ~/Developer
.
Clone the Solana repo and then move into the Solana directory:
git clone https://github.com/solana-labs/solana.git
cd solana
Now let's use Cargo to compile the Solana source code:
cargo build
Next run the install script. This will take a little while, so feel free to go grab a coffee while you wait.
./scripts/cargo-install-all.sh .
Finally, update your PATH
so Terminal knows where to find the Solana CLI commands:
export PATH=$PWD/bin:$PATH
5. Play around!
If you've made it this far, congratulations! You've successfully downloaded the Solana source code and used Rosetta to compile it to run on your M1 Mac.
Let's verify everything is working as expected. First make sure you can use the Solana CLI command:
solana
And now for the moment of truth, let's spin up a local test validator!
solana-test-validator
If everything is configured correctly, the validator will start running and print out its status like this:
You now have a Solana validator running on your local machine and can run commands like solana balance
and solana transfer
to submit transactions to your own personal devnet.
Notes
If you run into any issues while following this guide, please let me know in the comments or DM me on Twitter so I can publish a revision. Can't wait to see what you build!
Posted on October 1, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.