Tag Archives: npm

Upgrading Node.js using npm

The Node.js ecosystem provides a tool to update Node from within npm called, simply, “n”.

Install n thus:

[bash]
sudo npm cache clean -f
sudo npm install -g n
[/bash]

I don’t know that clearing the cache is actually necessary, but a number of people have recommended doing so.

Update to the latest version of node using:

[bash]
sudo n stable
[/bash]

n allows node versions to be changed easily. The n package listing has details.

Strange npm Errors

I’ve gotten some strange errors with npm which were resolved by clearing npm’s cache. The brute force method is:

[bash]
sudo npm cache clean -f
[/bash]

This falls under the same category as strange C/C++ behaviour resolved by removing all .o files, strange Python behaviour resolved by removing all .pyc files. Caching or otherwise keeping around intermediaries is a boon for speed, but can bite when the cache gets stuffed up.