As you may already know, npm is currently bundled with Node.js. It means that if you have installed Node.js, you've already installed npm as well.
Also, pay attention to the Node.js and npm release versions table that shows us approximate versions compatibility. Sometimes, versions discrepancy may cause incompatibility errors.
So, if you're a developer, it's kind of "best practice" to manage your development environment using one of the Node.js version managers.
Here is a list and usage notes of some of the most popular:
Homebrew (macOS)
If you're on macOS, you can use Homebrew.
Actually, it's not just a Node.js version manager.
To install Homebrew to your Mac:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
To install Node.js and npm using Homebrew, run:
brew install node
Later, you will be able to update them using:
brew update && brew upgrade node
Also, you can switch between Node.js versions as well:
brew switch node 0.10.26
npm will be upgraded/downgraded automatically.
n (macOS, Linux)
n is most likely to rvm (Ruby Version Manager), and is used to manage Node.js and npm versions simultaneously. It is written on pure Linux shell, and available as an npm module. So, if you already have any Node.js version installed, you can install/update the n package through npm:
npm install -g n
Downloading, installing and switching to Node.js and npm versions is as easy as:
n 0.10.26
n 0.8.17
n 0.9.6
To download, install, and switch to the latest official release, use:
n latest
To download, install, and switch to the latest stable official release, use:
n stable
To switch to the previously active version (aka $ cd -
), use:
n prev
If you want to see the list of installed Node.js versions, just run n
from your command line. The output will be something like the following:
n
Output:
0.10.26
• 0.8.17
0.9.6
Where the dot (•) means that it's a currently active version. To select another Node.js version from the list, use Up/Down arrow keys and activate using the Enter key.
To list the versions available to install:
n lsr
nvm (macOS, Linux)
nvm is also like rvm, even the command names and usage are very similar.
To install nvm, you can use the installation script (requires Git) using cURL
:
curl https://raw.github.com/creationix/nvm/master/install.sh | sh
or Wget:
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh
To download and install a specific Node.js and npm version, use:
nvm install 0.10
Then, you can switch to the installed version, using:
nvm use 0.10
Also, you can create the .nvmrc file containing the version number, then switch to the specified version using the following command:
nvm use
To see the list of installed Node.js versions, use:
nvm ls
To list the versions available to install:
nvm ls-remote
nvm-windows (Windows)
nvm-windows is a Node.js version management utility for Windows, ironically written in Go.
It is not the same thing as nvm. However, the usage as a Node.js version manager is very similar.
To install nvm-windows, it is required to uninstall any existing versions of Node.js and npm beforehand. Then, download and run the latest installer from releases.
To upgrade nvm-windows, run the new installer. It will safely overwrite the files it needs to update without touching your Node.js installations.
nvm-windows runs in an Admin shell. You'll need to start PowerShell or Command Prompt as Administrator to use nvm-windows.
Before using, you may also need to enable nvm-windows with the following command:
nvm on
To download and install a specific Node.js and npm version, use:
nvm install 0.12
Then, you can switch to the installed version, using:
nvm use 0.12
If you want to see the list of installed Node.js versions, use:
nvm list
To list the versions available to install:
nvm list available
nvm
wich gives you the option to have more than one running versions of node+npm – Inglis