简体   繁体   中英

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

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++'

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)

Install nvm version > 0.3.7 and install node version >= 16.0

Use the following command for successful install:

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

before the above command, please be sure to have .zshrc file in the root of your current username folder ( ~/ ).

it wasn't an issue while i was trying to install node 12.XX 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

I found a solution that really worked well here, am not going to write the entire steps please follow this link [Rosetta Terminal]

You can set up the following commands:

  • nvm
  • node
  • npm

and for Rosetta-emulated Intel versions:

  • nvm86
  • node86
  • npm86

This way, you can use the native versions - and if you hit incompatibility issues, you can use the Rosetta-emulated Intel variants of nvm/node/npm.

I posted a guide on how to achieve this here .

The best instructions are on nvm 's own Readme's FAQ on Macs with M1 processors:

https://github.com/nvm-sh/nvm#macos-troubleshooting

I did the following:

Run software update: softwareupdate --install-rosetta --agree-to-license

Error in Rosetta Updater, but you can: grep RosettaUpdateAuto.pkg /var/log/install.log

and just: open /path/to/RosettaUpdateAuto.pkg

After that, right-click your terminal icon in dock > Open > Options > Show in Finder.

Then, right-click > Get Info.

Then, check 'Open using Rosetta'

In the terminal you can check you are using rosetta with: arch

Then just: nvm install v6.9.1 # for example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM