nvm install node fails to install on macOS Big Sur M1 Chip

22,270

Solution 1

If you have installed nvm using homebrew and trying to install the node using command nvm install <some_version>, you will face errors on apple silicon machines (ARM) until the node version is higher than 14. Node versions older than 15 does not work on apple silicon machines (ARM) because ARM architecture is not supported by node older versions. For anything under v15, you will need to install node using Rosetta 2.

  1. How to open terminal in Rosetta2 mode -> got to Application -> right click on terminal app -> get Info -> Select "Open using Rosetta" -> Restart Terminal
  2. In Terminal, write -> arch -x86_64 zsh Now you will able to install any version of node (even multiple versions)

Solution 2

it wasn't an issue while i was trying to install node 12.X.X but below that it was a big pain so i followed below steps and it worked for me

Uninstalled nvm if it’s already installed using Homebrew.

brew uninstall nvm
brew cleanup

Install Rosetta

softwareupdate --install-rosetta

Make terminal/iTerm2 to open in Rosetta mode

got to Application (-> utilities) -> right click on terminal app -> get Info -> Select "Open using Rosetta" -> Restart Terminal

In Terminal run a command

arch -x86_64 zsh 

Make sure machine has .zshrc file if not just create one

cd ~
touch .zshrc

Install NVM

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

And it should add the below piece of code to .zshrc

Restart the terminal and check if nvm is installed successfully by running

nvm -v

Then install Node with nvm as usual

nvm install 10
Share:
22,270
adityaatri
Author by

adityaatri

Updated on July 09, 2022

Comments

  • adityaatri
    adityaatri almost 2 years

    I'm trying to install the latest version of node using nvm. I've just got the newly released SIlicon Macbook Pro with the M1 chip (not sure if that is related). I've installed xcode on the app store and the xcode tools on the command line. The main error i'm getting is:

    clang: error: no such file or directory: 'CXX=c++'
    
  • LJHarb
    LJHarb almost 3 years
    (nvm maintainer here) note that nvm is explicitly not supported when installed via homebrew - the only correct way to install it is with the install script in nvm's readme.
  • Sahil Paudel
    Sahil Paudel over 2 years
    I am getting arch: posix_spawnp: zsh: Bad CPU type in executable
  • africola
    africola over 2 years
    I installed via the nvm install script and ran into the same error -- and the steps by @adityaatri to run Terminal or iTerm2 in Rosetta mode also worked for me.
  • superandrew
    superandrew over 2 years
    if I understood correctly, you will neither do 1) OR 2), not together
  • user1978019
    user1978019 over 2 years
    I first needed to install Rosetta. This was all I did, WITHOUT opening the terminal using right click etc. 1. install nvm via the script at the github repo (not homebrew) 2. softwareupdate --install-rosetta 3. arch -x86_64 zsh 4. nvm install 14.8.0
  • raman
    raman over 2 years
    Thanx alot, it saved me alot of time.
  • Tyler2P
    Tyler2P over 2 years
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
  • Maitraiya Mali
    Maitraiya Mali about 2 years
    Step 1 was optional for me, Step 2 did the trick for me
  • Dylan Wright
    Dylan Wright almost 2 years
    This is to install nvm, not how to install a version of node using nvm
  • Noah Ispas
    Noah Ispas almost 2 years
    can confirm this worked for me as well