DEV Community

loading...

Installing nodejs on macOS Apple Silicon (M1)

mkbaldwin profile image Michael Baldwin Originally published at michael.codes on ・2 min read

I recently bought a new MacBook Pro with the M1 Apple Silicon CPU. While most things seem to be working great, some developer tools are not yet distributed as native aarch64 binaries. Currently, nodejs is one of those tools. The developers are working on official support, but it isn’t available yet. Fortunately thanks to the nvm project it is still easy to get up and running.

First, if you do not already have the xcode command line tools installed you should install them. This will download the needed C++ compiler and other development tools. Do this by running:

sudo xcode-select --install
Enter fullscreen mode Exit fullscreen mode

Once that completes, install nvm per their instructions. The command will look something like the following (to ensure you get the latest version of nvm use the command from Github).

Note that if you do not already have a profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) for your shell it won’t be able to install correctly. You should create the appropriate file(s) first before running the command below.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

Now that you have nvm installed you can run the following command to install node. Version 15 is the one that currently (Jan 2021) works on aarch64 for Mac.

nvm install v15
Enter fullscreen mode Exit fullscreen mode

If everything works correctly this step will take a while to compile everything and copy the newly buily node to the correct install location inside the ~/.nvm directory. After the build and install completes test the install by running:

node --version
Enter fullscreen mode Exit fullscreen mode

You will probably need to close and re-open your terminal for the command to be found.

Finally, you will want to clear the nvm cache to reduce clutter. After the build mine was consuming about 11GB, vs about 100MB once the cache was cleared. This can be done using:

nvm cache clear
Enter fullscreen mode Exit fullscreen mode

Hopefully, this helps someone else that is also on the bleeding edge of Apple hardware!

Discussion (1)

pic
Editor guide
Collapse
walkingriver profile image
Michael D. Callaghan

I am a huge fan of nvm and just used it to install Node 15.8.0 on my M1 Mac mini. The Activity Monitor still shows its architecture as "Intel," though. Any thoughts?