Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 596
Sventies Avatar asked Dec 17 '20 14:12

Sventies


People also ask

Is Node.js available for M1 Mac?

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.

Does Homebrew work on M1 Mac?

If you're coming to M1 Mac fresh, without any old projects or profiles, you probably won't notice; Homebrew will work as it always has. But if you're trying to migrate from an Intel Mac you won't be able to just move packages that were once in /usr/local over to /opt/homebrew .


5 Answers

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'
like image 71
Sators Avatar answered Oct 19 '22 13:10

Sators


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).

like image 29
Mark Avatar answered Oct 19 '22 15:10

Mark


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
like image 36
luisdemarchi Avatar answered Oct 19 '22 14:10

luisdemarchi


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
like image 5
chenrui Avatar answered Oct 19 '22 14:10

chenrui


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

like image 3
iDecode Avatar answered Oct 19 '22 13:10

iDecode