How To Install nodejs, npm, nvm on macOS Apple Silicon (Mac M1)
Let's get to installing Nodejs, npm and nvm right away on your Macbook with Apple Silicon M1 processor.
First, You should go ahead and create a profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) for your shell if you do not have one already.
Next, 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
Thanks to the awesome developers and community maintainers of Node, you can install Node natively on ARM (Apple Silicon M1 / Mac M1) by installing the latest version 15.6.0 of Node. The older versions of Node will still work on Mac M1, however you will need Rosetta 2 to run it properly. Let's get started:
1. Install nvm (Node Version Manager)
# run this command in Terminal
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
2. Install NodeJS version 15
nvm install v15
You may be prompted to install command line developer tools if you haven’t already. Install them and you may need to run the command again. Nvm will build Node from source, which will take a while (around 10 minutes for me).
3. Now, kindly verify that NodeJS and npm were installed correctly
# check for node
node -v# check for npm
npm -v
It is recommended to clear your cache after the build and installation. This can be done using:
nvm cache clear
For instance, after the build my system node was consuming about 9GB, and then after clearing cache, about 100MB.
The installation took about 20 minutes for me. However, what was stunning and unbelievable was the macbook had not heated up one bit. The temperature of the device was what it was before when the Node installation started. Also, the fan did NOT run at all. This is a Macbook Pro with M1 chip. Un-f-believable!