I had some fun yesterday setting up a new Gruntfile. I copied over the package.json files and wanted to update the versions of the packages. Unfortunately I started hitting errors because my versions of NPM and Node were out of date. I knew I could just go download the node package, but I decided to find another way.

First, update node

Low and behold, you can use NPM to update node itself!

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

First this clears out the NPM cache to make sure we can get the latest information from NPM. I then install n globally which is a utility for updating Node. Once installed, I can use it to update Node to the latest stable version. Had I wanted to install a specific version, I can call it out with n 0.10.26.

Second, update NPM

Once Node is updated, NPM is a simple matter as well.

npm update -g npm

This command tells NPM to update NPM globally with the latest stable. Once both Node and NPM are updated, other packages update without trouble.