Thanks for wanting to contribute!

You have one more step.
Your email address will not be published.

Dual Install homebrew, nvm, and node on Apple M1

Even though Homebrew is supported on Apple M1 Silicon, not all packages will work. So if you’re like me, you’ll still need to use the x86 installation of Homebrew (I’m waiting on you, node-sass).

Good news! You can dual install both M1 and x86 versions on homebrew, nvm, and node.

Make a duplicate of your Terminal for Rosetta 2

Go to your Applications folder and locate Terminal (or your preferred terminal), and right click on the terminal icon and choose Duplicate.

This will create another copy of the terminal in the folder, rename this copy to “Rosetta Terminal”.

Right click on the newly created copy and choose Get Info, and mark the Open with Rosetta option checked.

Congratulations! You now have an x86 terminal and an ARM terminal!

Install x86 Homebrew in Rosetta Terminal

Open Rosetta Terminal, and use the following command to install Homebrew.

/bin/bash -c "$(curl -fsSL"

You will be prompted for your password and the script will ask for verification on the install location.

Make sure the root of the install is /usr/local/*! This will be inportant in differentiating the two versions of Homebrew.

Let the script run, and we can move on to the ARM Homebrew installation.

Install ARM Homebrew on Apple M1

Open Terminal (not “Rosetta Terminal”!), and run the Homebrew installation script again.

/bin/bash -c "$(curl -fsSL"

This time, make sure the root of the install is /opt/homebrew/*.

Boom! Now you have Homebrew installed for each terminal.

Now for the tricky part of dual-installing nvm and node.

Dual-install nvm for x86 and ARM Homebrew

If you are familiar with javascript development, you’ll know that nvm is a great tool for working across multiple projects. Nvm uses directories to keep track of each node version and this will be key in the dual-installation.

First, go to either terminal and run the following command to create the two directories for each nvm library.

mkdir ~/.nvm-x86 ~/.nvm

Next, go to each terminal and install nvm through Homebrew.

brew install nvm

Now here’s the most important part!. Once each version of nvm is installed, each version will need to know which package library to use based on the terminal.

To do this, create or open ~/.zshrc in your text editor and update it with the following text.

if [ "$(sysctl -n sysctl.proc_translated)" = "1" ]; then
    local brew_path="/usr/local/homebrew/bin"
    local brew_opt_path="/usr/local/opt"
    local nvm_path="$HOME/.nvm-x86"
    local brew_path="/opt/homebrew/bin"
    local brew_opt_path="/opt/homebrew/opt"
    local nvm_path="$HOME/.nvm"

export PATH="${brew_path}:${PATH}"
export NVM_DIR="${nvm_path}"

[ -s "${brew_opt_path}/nvm/" ] && . "${brew_opt_path}/nvm/"  # This loads nvm
[ -s "${brew_opt_path}/nvm/etc/bash_completion.d/nvm" ] && . "${brew_opt_path}/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

Save the file, and either restart your terminals or run source ~/.zshrc in each terminal.

Now you are safe to install node in each terminal.

nvm install node

Boom! Now you have the flexibility to use node in your Apple M1 terminal, and use the Rosetta terminal as a fallback if your required packages are not ready for Apple Silicon!

You Might Also Like...

2 responses to this post

  1. pablito25sp

    local brew_opt_path=”/opt/homebrew/bin”
    should be
    local brew_opt_path=”/opt/homebrew/opt”

    great doc!

Leave a Reply

Your email address will not be published.

Get Connected With Me

I'll never share your email with anyone else.