DEV Community

Cover image for How to install Solana dev tools on an M1 Mac
Nicholas Garfield
Nicholas Garfield

Posted on • Edited on

How to install Solana dev tools on an M1 Mac

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

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

πŸ§πŸ˜•

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.

Screen Shot 2021-09-29 at 11.38.58 AM

Now we can go ahead and cleanly uninstall everything. Let's first uninstall Solana:

rm -rf /Users/USERNAME/.local/share/solana/
Enter fullscreen mode Exit fullscreen mode

And then uninstall Rust:

rustup self uninstall
Enter fullscreen mode Exit fullscreen mode

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

Now navigate back to your Finder window and create a duplicate copy of the Terminal application.

Screen Shot 2021-10-01 at 12.30.51 PM

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.

Screen Shot 2021-10-01 at 12.35.23 PM

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

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

Let's also install Coreutils and OpenSSL:

arch -x86_64 brew install coreutils openssl@1.1
Enter fullscreen mode Exit fullscreen mode

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

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

Now let's use Cargo to compile the Solana source code:

cargo build
Enter fullscreen mode Exit fullscreen mode

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

Finally, update your PATH so Terminal knows where to find the Solana CLI commands:

export PATH=$PWD/bin:$PATH
Enter fullscreen mode Exit fullscreen mode

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

And now for the moment of truth, let's spin up a local test validator!

solana-test-validator
Enter fullscreen mode Exit fullscreen mode

If everything is configured correctly, the validator will start running and print out its status like this:

Screen Shot 2021-10-01 at 4.04.29 PM

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!

Top comments (25)

Collapse
 
pradan profile image
Prashant Dandriyal

Hi Nick. Kudos for the good work. Just wanted to point out that while installing arch -x86_64 brew install openssl@1.1 on the rosetta terminal, I got this brew error:

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

I don't know why this wasn't experienced by anybody else. I am looking into this and would like to know if someone already solved it. 🀠

Collapse
 
abhi3700 profile image
Abhijit Roy • Edited

Finally! I resolved this issue. Now, I am able to start a localnet node in my Mac M1.

From this step where, you are stuck, just continue installing under ARM architecture. Then, follow my notes here. github.com/abhi3700/sol-playground...

You will be able to run on M1. I tested for Solana version 1.8.5.

Collapse
 
abhi3700 profile image
Abhijit Roy

Even I am facing this same issue.

Would like to hear from reply from others

Collapse
 
mizi_san_ profile image
Mizi San

I wasn't able to run ./scripts/cargo-install-all.sh .

Collapse
 
aekasitt profile image
Sitt Guruvanich

According to this commit on Solana repo, I think you need to install greadlink first using the following command

arch -arm64 brew install coreutils
Enter fullscreen mode Exit fullscreen mode
Collapse
 
cervoneluca profile image
Luca Cervone

at line 13 of cargo-install-all.sh

change this:

cargo="$("${readlink_cmd}" -f "${here}/../cargo")"

to this:

cargo="cargo"

then run

./scripts/cargo-install-all.sh .

It should work

Collapse
 
saturn profile image
saturn • Edited

For anyone who might encounter this, after editing the cargo-install-all.sh file I would get:
zsh: operation not permitted: ./scripts/cargo-install-all.sh
Apple apparently puts the file in quarantine, running
xattr -d com.apple.quarantine solved it !

Collapse
 
cervoneluca profile image
Luca Cervone • Edited

anyway, do not use

git clone https://github.com/solana-labs/solana.git

Since it will download the current version of Solana, that right now (November, the 7th 2021), is the 1.9.0. Even if this version will build and install correctly on M1 macs, you'll have issues later when you try to send transactions to the Solana network.

Instead, download the 1.8.2 version and follow all the above steps.

Collapse
 
robbie_white_52dcb9f0c821 profile image
robbie white

I am at the point where I have to setup config file so Cargo knows how to compile Rust codes, I did not have a folder named config so I created that, then in that folder I created a file and named it rust code and pasted the given code in. and when I run cargo build I get an error saying it could not find cargo.toml
Am i doing something wrong?

Collapse
 
robbie_white_52dcb9f0c821 profile image
robbie white

ok so i figured it out, you do not make a folder, you just make the file and name it config. so that fixed that.

Collapse
 
dige93 profile image
dige93

MacBook-Pro ~ % solana-test-validator
dyld[19265]: Library not loaded: /usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib
Referenced from: /Users/dige/.local/share/solana/install/releases/1.8.5/solana-release/bin/solana-test-validator
Reason: tried: '/usr/local/opt/openssl@1.1/lib/libssl.1.1.dylib' (no such file), '/usr/local/lib/libssl.1.1.dylib' (no such file), '/usr/lib/libssl.1.1.dylib' (no such file)
zsh: abort solana-test-validator

Can't find a solution to this.

Collapse
 
robbie_white_52dcb9f0c821 profile image
robbie white

I am having a problem with the updating my path, I went to the .zshrc and added the given path and it when I do the last step to see if solana is working I get and error saying command not found. any help or ideas of what I may have done wrong?

Collapse
 
csjcode profile image
CSJcode

I'm using bash but just did the following and it worked fine, should work if you fill in ~/.zshrc:

echo 'export PATH=$PWD/bin:$PATH' >> ~/.bash_profile

Collapse
 
csjcode profile image
CSJcode

Thank you for taking the time and effort to do this. This was very helpful fixing validator errors after I got my new M1 mac. I did have to do some additional minor config edits, such as suggested by Luca Cervone in the discussion here... but your article got me 95% there. Thanks!

Collapse
 
indie_republik profile image
indieRepublik

I tried to run the solana-test-validator and got message: Notice! No wallet available. solana airdrop localnet SOL after creating one

Ledger location: test-ledger
Log: test-ledger/validator.log
⠁ Initializing... zsh: illegal hardware instruction solana-test-validator

Collapse
 
bluenights004 profile image
Ocean&Sky

Hi newbie in solana dev here, I got stuck at step "cargo build" (after compiling solana source code) receiving error: failed to run custom build command for tikv-jemalloc-sys v0.4.2+5.2.1-patched.2

Here's my current rust and other dependencies version and using Mac M1 hardware.

Image description

I also tried to use sudo apt update but no avail. However on this site substrate.stackexchange.com/questi..., i found answer that suggesting to manually update to current version of tikv-jemalloc-sys, maybe this can be a solution but no knowledge on how to do that.

Collapse
 
nimishmadan98 profile image
Nimish • Edited

I am able to run solana-test-validator but when I open other terminal to execute solana commands it gives "-bash: solana: command not found". Could someone please help here?
Also if I close the terminal and start again, I have to do all the steps again.