'Install Node on M1 Mac
Kind of a noob here on questions about binaries, processors and how that all works together:
I have a new Mac with an M1 chip, and want to install Node. I'm used to do this with Homebrew. Now, if I install Homebrew, I'm strongly recommended to use Rosetta, so I did. Next step: installing Node. So instead of brew install node I do arch -x86_64 brew install node.
This works fine, only I'm wondering, am I now using node in a sub-optimal way? Is Node also using Rosetta, instead of directly running on the M1 chip?
Solution 1:[1]
Depending on your project dependencies, you might find it necessary to run node on an x86 architecture as it may get you past frustrating errors on older versions of node. If like me you had already installed node in your attempts here, you can use the following to help get you sorted (assuming you have already installed NVM):
$ nvm uninstall 14
$ arch -x86_64 zsh
$ nvm install 14
$ nvm alias default 14
Consider replacing 14 above with whichever node version you are attempting to run under.
After installing, you can run node followed process.arch to confirm that node is running in x64 mode:
$ node
> process.arch
'x64'
Solution 2:[2]
From node v16.x:
https://doesitarm.com/app/nodejs/
PS: node v16 has problems with serverless-offline. I managed to solve it using node v15.4.0
From node v15.x:
sudo xcode-select --install
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install v15
node --version
Solution 3:[3]
To install Node 15.6.0 or higher:
Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashInstall NodeJS
nvm install v15
To verify if both nvm and NodeJS were installed successfully, run:
node -v
npm -v
You can find more information here
Solution 4:[4]
As Node v16 natively supports Apple Silicon, brew install node or nvm install 16 would work on the Apple M1 laptops.
Here is my current build.
$ nvm --version
0.39.0
$ node --version
v16.13.1
$ node -p "process.arch"
arm64
Solution 5:[5]
Nvm install 14.15.3 (current LTS) wasn't successful for me in any of the attempts (with brew arch -x86_64 prefix as well). But, I was able to:
- install nvm from github (with putting the "export" string to ~/.zhrc and executing it)
- nvm install 15
Note: This VSCode version works for me as well: https://code.visualstudio.com/docs/?dv=osx&build=insiders
Solution 6:[6]
Open Terminal Using Rosseta 2 if you haven't installed rosseta2 yet Just Check out my blog to set up it
https://siddhantjohari.medium.com/setting-up-react-native-in-mac-m1-aaf18c37fc34
Install Homebrew using this command.
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Now hit this command to install nodejs or anything you want
arch -x86_64 brew install <package>
Thank you.
Solution 7:[7]
you can install node using n, please follow the link.
n --arch arm64 16
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sators |
| Solution 2 | Basil Bourque |
| Solution 3 | iDecode |
| Solution 4 | chenrui |
| Solution 5 | Lazyexpert |
| Solution 6 | SIDDHANT JOHARI |
| Solution 7 | Mohammadreza Abdoli |

