Install NodeJS & NPM

Install multiple versions

First, need to install nvm. Run the line of curl and then run/add-to-zsh the line of export.

<aside> ⚠️ Below commands are mostly for Linux/MacOS users.


<aside> ⚠️ For Mac M1: You may encouter error Target architecture arm64 is only supported on arm64 and x64 host when installing NodeJS version <= 14 with nvm. Just open Terminal using Rosetta (right click on > Get info > tick "Open using Rosetta") and then run the installation command again. 💡 Tip: You can create a separated Terminal just in case you wanna install something using Rosetta.


# FIRST INSTALL: the most recent lts release
nvm install --lts
# install a specific version
nvm install 12.13.0
# install latest version
nvm install node
# list all installed versions
nvm ls
# set default version of node
nvm alias default 12.13.0
# full list of available versions
# be careful, it's too long!!!
nvm ls-remote
# switch between versions
nvm use 12.13.0
# or (more quickly)
nvm use v15
# uninstall some version
nvm uninstall 12.13.0

Single version

# UPDATE npm
npm cache clean -f # clear the cache first
sudo npm install -g npm
# UPDATE node
sudo npm install -g n
sudo n stable
# refresh the shell
source ~/.zshrc # if using zsh
source ~/.bashrc # is using bash
# Check version
npm -v
node -v

Shorthand CLI options

Install packages