node.js - How can I update NodeJS and NPM to the next versions?

ID : 497

viewed : 138

Tags : node.jslinuxnpmnode-modulesnpm-updatenode.js

Top 5 Answer for node.js - How can I update NodeJS and NPM to the next versions?

vote vote

100

See the docs for the update command:

npm update [-g] [<pkg>...] 

This command will update all the packages listed to the latest version (specified by the tag config), respecting semver.

Additionally, see the documentation on Node.js and NPM installation and Upgrading NPM.

The following original answer is from the old FAQ that no longer exists, but should work for Linux and Mac:

How do I update npm?

npm install -g npm 

Please note that this command will remove your current version of npm. Make sure to use sudo npm install -g npm if on a Mac.

You can also update all outdated local packages by doing npm update without any arguments, or global packages by doing npm update -g.

Occasionally, the version of npm will progress such that the current version cannot be properly installed with the version that you have installed already. (Consider, if there is ever a bug in the update command.) In those cases, you can do this:

curl https://www.npmjs.com/install.sh | sh 

To update Node.js itself, I recommend you use nvm, the Node Version Manager.

vote vote

89

I found this really neat way of updating node on David Walsh's blog, you can do it by installing n:

sudo npm cache clean -f sudo npm install -g n sudo n stable 

It will install the current stable version of node.


EDIT: Please don't use n anymore. I recommend using nvm. You can simply install stable by following the commands below:

nvm ls-remote nvm install <version>  nvm use <version> 
vote vote

78

Updating npm is easy:

npm install npm@latest -g 
vote vote

62

I understand this question is for Linux machine but just in case anybody is looking for a Windows solution, just go to the Node.js site, click the download button on the homepage and execute the installer program.

Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest 0.8.15 Node.js version running on my Windows 7 machine.

vote vote

53

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 

Top 3 video Explaining node.js - How can I update NodeJS and NPM to the next versions?

Related QUESTION?