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>
<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 Terminal.app > Get info > tick "Open using Rosetta") and then run the installation command again. 💡 Tip: You can create a separated Terminal Rosetta.app just in case you wanna install something using Rosetta.
</aside>
# 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
# 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
i
: install
D
: -save-dev
(devDependencies
)P
: -save-prod
(default), -save
g
: -global
f
: -force
ls
: list