Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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++'
like image 954
adityaatri Avatar asked Apr 25 '21 14:04

adityaatri


People also ask

Does node work on Mac M1?

So far, the transitions are pretty smooth, and many developer tools have also been updating their latest versions to work natively with the M1 machine (yes, including docker). If you are installing Node. js, I recommend using Node Version Manager (nvm) over Homebrew.

Should I install NVM before node?

Node Version Manager, more commonly called nvm, is the most popular way to install multiple versions of Node.js, but is only available for Mac/Linux and not supported on Windows. Instead, we recommend installing nvm-windows and then using it to install Node.js and Node Package Manager (npm).

Why can’t I install NVM on Apple Silicon Machines (ARM)?

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.

Does NVM build from source on a Mac M1 CPU?

It looks like running nvm install v15 on a Mac M1 CPU does build from source, but it still produces an x64 binary. This can be verified using node -p process.arch -> it prints x64 instead of arm64. However, building node from source using homebrew creates a correct arm64 build. I'm not sure if this should be reported as a separate issue.

How do I install node on Big Sur?

Install Node manually, by Homebrew, by nvm and also downgrade npm to various lower versions. Reinstall Homebrew to get fresh background as it was used before upgrade to Big Sur.

What is node version manager (NVM)?

Using Node Version Manager (NVM) it is possible to switch between different Node.js versions on the fly. It also allows testing code with older Node.js versions. NVM is a shell script used for installing and managing Node.js on a Unix based system.


2 Answers

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)
like image 52
adityaatri Avatar answered Sep 16 '22 11:09

adityaatri


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
like image 25
aatif shaikh Avatar answered Sep 20 '22 11:09

aatif shaikh