Install Node on M1 Mac
Asked Answered
Z

8

54

I have a new Mac with an M1 chip, and want to install Node. I 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?

Zarathustra answered 17/12, 2020 at 14:39 Comment(1)
Always do a brew info node if your is install not ok. For eg., brew info node@16 gives you that command to make it running correctly echo 'export PATH="/opt/homebrew/opt/node@16/bin:$PATH"' >> ~/.zshrc.Guenzi
H
24

I just got my M1 Mac mini. I did add an alias since I use oh-my-zsh to my ~/.zshrc for alias brew=arch -x86_64 brew so I don't have to keep typing all that. I brew install nvm then nvm ls-remote and installed v15.5.0. It gets built DV8_TARGET_ARCH_ARM64.

Hope that helps. I also pulled the insiders VSCode for ARM64. Loads in a second.

> node -p "process.arch" arm64

Don't forget you need xcode-select --install command line tools (~450MB).

Heber answered 25/12, 2020 at 14:36 Comment(3)
This seems to work pretty good, but in my case i still get "x64" back, even tho, i've uninstalled node and made a new clean install via arch -x86_64 zsh.Kennard
For anyone looking at this answer, it's inadvisable to alias "brew". You should have both the ARM and Intel versions of Brew installed. "brew" should remain brew. Alias the x86 version to something like "brewx86".Havens
Yeah the age of my original post is no longer applicable. No one should be having issues anymore.Heber
S
51

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'
Shiff answered 9/6, 2021 at 15:25 Comment(5)
See also the M1 docs here: github.com/nvm-sh/nvm#install--update-scriptHoliness
whenever i change arch with $ arch -x86_64 zsh, then i got nvm command not foundErlking
@RohrFacu Try running source ~/.profile before running nvm...?Shiff
How to change this back ?! @ShiffHophead
@Hophead Try arch -arm64 zshWheaten
H
24

I just got my M1 Mac mini. I did add an alias since I use oh-my-zsh to my ~/.zshrc for alias brew=arch -x86_64 brew so I don't have to keep typing all that. I brew install nvm then nvm ls-remote and installed v15.5.0. It gets built DV8_TARGET_ARCH_ARM64.

Hope that helps. I also pulled the insiders VSCode for ARM64. Loads in a second.

> node -p "process.arch" arm64

Don't forget you need xcode-select --install command line tools (~450MB).

Heber answered 25/12, 2020 at 14:36 Comment(3)
This seems to work pretty good, but in my case i still get "x64" back, even tho, i've uninstalled node and made a new clean install via arch -x86_64 zsh.Kennard
For anyone looking at this answer, it's inadvisable to alias "brew". You should have both the ARM and Intel versions of Brew installed. "brew" should remain brew. Alias the x86 version to something like "brewx86".Havens
Yeah the age of my original post is no longer applicable. No one should be having issues anymore.Heber
J
19

From node v16.x:

enter image description here https://doesitarm.com/app/nodejs/

enter image description here

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
Jovia answered 5/7, 2021 at 15:2 Comment(1)
Good solution for those of us who do not want to get involved with Homebrew.Glochidiate
H
11

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
Hunchbacked answered 13/12, 2021 at 20:55 Comment(0)
F
5

To install Node 15.6.0 or higher:

  1. Install nvm:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
    
  2. Install 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

Foeman answered 13/12, 2021 at 8:20 Comment(0)
S
1

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

Shirleenshirlene answered 3/1, 2021 at 18:57 Comment(2)
Looks like they have a open issue on v14 github.com/nodejs/build/issues/2474 good point.Heber
The issue appears to be that node v14 and earlier use versions of v8 which don't build for apple silicon, so they'd have to backport the v8 changes that allow it to build in order to release a node 12 or node 14 for apple silicon. Kinda annoying, but understandable :-/Saintmihiel
B
1

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.

Befitting answered 7/4, 2021 at 5:20 Comment(0)
C
-1

you can install node using n, please follow the link.

n --arch arm64 16
Castellan answered 22/9, 2021 at 9:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.