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 kinda "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
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:
C:\> nvm on
To download and install a specific node.js and npm version, use:
C:\> nvm install 0.12
Then, you can switch to the installed version, using:
C:\> nvm use 0.12
If you want to see the list of installed node.js versions, use:
C:\> nvm list
To list the versions available to install:
C:\> nvm list available
nvm
wich gives you the option to have more than one running versions of node+npm – Искрен Станиславов