Install StarkNet Cairo lang on macOS 12.1 Monterey on M1 MacBook Pro

I just started my journey in development for StarkNet. It is very exciting, but also immediately painful. It’s new tech, so it’s still all half broken.

Specifically, I am trying to install cairo-lang on my new MacBook Pro with M1 chip and macOS Big 12.1 Monterey. But I get errors installing the package. 
It’s mainly due to the default Python version not matching (3.9 instead of 3.7), which causes a cascade of issues which includes pip and gmp not found.

Here I found a series of advices. The main one tried to make me install an x86 version of brew running on Rosetta, but I don’t want to install two versions of brew on my machine.

The second advice has worked well for me. Here is exactly what I did.

Installation steps

# Install brew if you didn't it already
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install python
brew install python 

# Then a dependency
brew install gmp

# Some more dependencies, but properly linking gmp (this is the fix)
CFLAGS=-I`brew --prefix gmp`/include LDFLAGS=-L`brew --prefix gmp`/lib pip3 install ecdsa fastecdsa sympy

# And finally, install cairo-lang
pip3 install cairo-lang

You should be ready to go! Otherwise try some other solutions from here.

Now start BUIDLing

Compile your first contract following the official instructions!

Subscribe to clacla.eth
Receive the latest updates directly to your inbox.
Verification
This entry has been permanently stored onchain and signed by its creator.