Managing Node.js versions on Linux is no longer a pain in the ass with NVM (Node Version Manager). It can install different versions of Node.js and NPM on a single machine, switch versions anytime you wish. And the best part is NVM is just a Bash script, truly a lightweight helper for both testing and production.
Downloading binaries from Node.js and update them manually every now and then is not a pleasant thing to do, and installing Node.js via package manager is usually not a good idea since it's not maintained by the core team and often outdated:
Notice on official website of Node.js
Installation
Install NVM with install.sh from its latest release, change v0.39.1 if newer version is released:
It's good practice to review shell scripts before executing them.
Check if it's installed:
nvm -v
Bash
0.39.1
Output
Troubleshooting
If you got nvm: command not found, you might need to restart the terminal session for the shell configuration to work. Or to force update:
Bash
source ~/.bashrc
Bash
Zsh
source ~/.zshrc
Bash
Usage
For full usage guide, use --help:
nvm --helpBash
Node Version Manager (v0.39.1)
Note: <version> refers to any version-like string nvm understands. This includes:
- full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
- default (built-in) aliases: node, stable, unstable, iojs, system
- custom aliases you define with `nvm alias foo`
Any options that produce colorized output should respect the `--no-colors` option.
Usage:
nvm --help Show this message
--no-colors Suppress colored output
nvm --version Print out the installed version of nvm
...
Note:
to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)
Output
Install Versions
To install the latest version of Node.js:
nvm install node
Bash
To install LTS (Long Term Support) version of Node.js:
nvm install --lts
Bash
To install certain version of Node.js and migrate NPM global packages from current version: