Solarian Programmer

My programming ramblings

How to upgrade Node.js on Mac OS X

Posted on April 29, 2016 by Paul

If you already have Node.js installed on your Mac you will need to upgrade it when a new version comes up. There are basically two ways to achieve this goal download the installer from Node.js or use the command line to upgrade Node.js.

A simple way to upgrade Node.js from the Terminal is to use the n version manager:

1 npm install -g n
2 npm cache clean -f

Now, if you have XAMPP installed on your Mac, you need to do an extra step before upgrading Node.js:

1 cd /Applications/XAMPP/xamppfiles/bin
2 sudo mv HEAD _HEAD

At this point upgrading Node.js is as simple as:

1 sudo n stable
2 npm update -g

For XAMPP users only, rename _HEAD back to the original HEAD:

1 cd /Applications/XAMPP/xamppfiles/bin
2 sudo mv _HEAD HEAD

You can check which versions of npm and Node.js you have on your system with:

1 node -v
2 npm -v

If you want to learn more about Node.js I would recommend reading Node.js 8 the Right Way by Jim R. Wilson:

Show Comments