Node.js - nvm notes

Manage multiple node.js versions with nvm

get nvm version

nvm --version

upgrade nvm

(
  cd "$NVM_DIR"
  git fetch --tags origin
  git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"

uninstall nvm

# remove nvm root directory
rm -rf "$NVM_DIR"

# remove from `.bashrc` or `.bash_profile`
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion

names of versions of node

node version name status
node 3 iojs End-of-Life
node 4 argon End-of-Life
node 6 boron End-of-Life
node 8 carbon Maintenance LTS
node 10 dubnium Active LTS
node 12 erbium Active LTS

list all node versions available for installation

nvm ls-remote

list installed versions of node

nvm ls

install node with nvm

# "node" is an alias for the latest version
nvm install node

# install a specific version of node
nvm install 13.3.0

# install the latest version of LTS line
nvm install --lts=carbon
nvm install --lts=dubnium
nvm install --lts=erbium

# install and migrate npm packages from specific versions of node
nvm install 13 --reinstall-packages-from=12

uninstall node with nvm

nvm uninstall v12.13.1
nvm uninstall 12.13.1
nvm uninstall 12

use a particular version of node

nvm use 12
nvm use 13

nvm use default
nvm use node
nvm use system

set default node version with nvm

nvm alias default 12.13.1
nvm alias default 13.3.0

default global npm packages

If you have a list of default npm packages you want installed every time you install a new version of node, create a default-packages file under $NVM_DIR.

# $NVM_DIR/default-packages
http-server
npm
npm-check-update
yarn
rimraf
serve

© 2020 | Paul Kim