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 and M1X

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.

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 https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

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 https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

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"
else
    local brew_path="/opt/homebrew/bin"
    local brew_opt_path="/opt/homebrew/opt"
    local nvm_path="$HOME/.nvm"
fi

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

[ -s "${brew_opt_path}/nvm/nvm.sh" ] && . "${brew_opt_path}/nvm/nvm.sh"  # 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...


13 responses to this post

  1. pablito25sp

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

    great doc!

  2. nickr

    Very helpful post, I think this
    local brew_opt_path=”/usr/local/opt”
    should be
    local brew_opt_path=”/usr/local/homebrew/opt”

  3. Whitney

    Thank you for this! I did an echo $NVM_DIR in Rosetta and am getting the /.nvm-x86, I but whenever I do nvm ls or any other command, it says zsh: command not found: nvm – but it works in my non-Rosetta terminal? Any suggestions on why it can’t find NVM? I successfully is

    1. Sean NicDao Post author

      Whitney, were you able to figure it out? If so, what was the solution?

      If not, can you confirm:

      1. Homebrew has been installed in both terminals?
      2. ~/.nvm-x86 has an installation of nvm
    1. Sean NicDao Post author

      Morgan, have you resolved this? If so, what was the solution?

      If not, can you confirm:

      1. Homebrew has been installed in both terminals?
      2. ~/.nvm-x86 has an installation of nvm
  4. John

    “Make sure the root of the install is…”

    How do you suggest doing that? The install script you’ve cited doesn’t allow for such a thing, does it?

  5. Andrei C

    @Morgan & @Whitney,
    Make sure you add the details in ‘source ~/.zshrc’ file before you run ‘brew install nvm’.

    @Sean NicDao I suggest moving the “Now here’s the most important part!.” section before ‘brew install nvm’ part.

    All the best!

  6. Matt

    You shouldn’t set brew path to “/usr/local/homebrew/bin” and add that to your PATH, as this changes to HOMEBREW_PREFIX for intel homebrew away from /usr/local, where it should be.

  7. GM

    fix this local brew_opt_path=”/usr/local/opt” -> local brew_opt_path=”/usr/local/homebrew/opt” and all issues will be gone

  8. Tom

    how do you uninstall the rosetta version
    running the uninstall from rosetta tries to uninstall the arm version


Leave a Reply

Your email address will not be published.

Get Connected With Me

I'll never share your email with anyone else.