Upgrade npm and node.js

As you may know, NPM is currently bundled with Node.js, it means that if you have installed node you already have installed npm. There are several approaches to keep up to date the Node.js and NPM, you need to use one of the following version managers:

Homebrew

If yo are on Mac, you can use Homebrew. To install NodeJS and NPM using brew:

later you will be able to update it using

NPM will be updated as well.

You also will be able to switch to the one of the previous versions if you need, for example:

To install brew to your Mac:

N

n is most likely to rvm (Ruby Version Manager), and can be used to manage and update node/npm versions.

Install Node.js versions easily:

Use (and install if missing) the latest official release:

Use/install the stable official release:

Switch to the previous version you were using:

If you want to see the list of installed nodes, just run n from your command line, the output will be something like the following:

The dot (•) means that it’s a currently active version. To select a node version from the list use up and down arrows and activate using enter.

The n package is written on pure linux shell and available as a npm module (contains package.json), so if you have any Node.js installed, you can install/update the n through the npm:

nvm is also like RVM, even the command names and usage are very similar.

To download, compile, and install the latest v0.10.x release of the Node.js using nvm:

And then you can switch to the installed version:

You can create an .nvmrc file containing version number in the project root folder; then run the following command to switch to the specified version:

Or you can just run it:

If you want to see which versions are already installed, use:

To install nvm itself you can use the install script (requires git) using cURL:

or wget:

P.S.

All these approaches I’ve used on MacOSX and Linux, I don’t have any experience on how to manage Node.js versions on Windows, I can only suppose that the n (the second one) will work for Microsoft’s OS (at least from the cygwin).

 

Leave a Reply

Your email address will not be published. Required fields are marked *