Installing node and npm

Updated November 2015

Posted by Ryan Lewis on August 10, 2015

Updated: November 4th 2015

Wow! Node hit 5.0 so quick, your head must still be spinning. With the release of 5.0, they’ve also introduced an LTS release. LTS is short for Long Term Support, which means it is the most stable of the stable. Eventually, it’s the version branch that will always work. LTS is on the 4.x version right now, whereas stable is on 5.x.

So, which one should you install? Well, it’s mostly up to your nature. The Node core group is generally very conscious to not introduce breaking changes, so using the newest and greatest (5.0 as of right now) should have no problems. But! That doesn’t mean there won’t be incompatibilities with a library you’re just itching to use. In that case, you might want to eye LTS. Also, I would definitely consider the LTS branch for production releases, since that release will be maintained much longer than the stable releases.

To break it down, install version 5+ if you’re the adventurous sort. If your job depends on the node version, I would stick with the LTS release. Either way, node finally getting out of pre-1.0 hell is reason to celebrate!

Updated: September 16th 2015

Node hit 4.0! Exciting times! No changes to installing but get out there and update!

Ps. Make sure to reinstall all node dependencies. Some compiled ones won’t work until you’ve reinstalled them.


Installation

So you want to install node? Maybe someone pointed you here from a Pluralsight class (hehe) or you’ve found this from a search engine. Well, you’ve come to the right place. I’ll keep this article up to date with the best ways to install node and npm on each of the major platforms. Leave a comment if you find any issues!

Mac OSX

Tools: Homebrew / Terminal

Homebrew is a package manager for OSX, similar to apt or yum. It will install programs on your mac with a single command. It’s quite handy, and it’s one of the easiest ways to install node on your mac. Make sure to install Homebrew for these steps to work.

Open your Terminal of choice and execute the command:

brew install node

This will download and install node. It may take some time, so go grab your brew of choice while you wait.

There may be some issues installing it, which can happen. Usually these happen due to brew not having permissions to access or write to files or directories. Brew has some of the best error messages I’ve ever seen, and typically they will tell you exactly what you need to do. (Sometimes you need to throw in a ‘sudo’ here or there as well).

Once everything has completed, try out the following commands to ensure everything is ready to go:

node --version

npm --version

These should output some version, which doesn’t matter as much as it outputting something. And that’s it!

PS. Brew might’ve given you a stale version of node. Check out the instructions at the bottom of this article to upgrade to the current version of node and npm.

Windows

Tools: Web Browser (you’re probably looking at one right now) / Command Prompt

Windows is getting its act together with the oneget package manager included with Windows 10, but since it’s still bleeding-edge, I’ll stick with the tried and true installer method for Windows. This section especially might be updated very soon with new instructions if oneget is successful.

Navigate to the node.js homepage and click on the (seriously) big, green ‘INSTALL’ button.

It looks like this

This should download (or prompt you to download) an installer (maybe .msi, maybe .exe). Say yes and let that bad boy finish downloading. When it’s done, open it up and follow the steps to finish installation.

Once the steps are done, open up your Command Prompt (cmd.exe if you’re searching) and enter the following commands:

node --version

npm --version

These should output some version, which doesn’t matter as much as it outputting something. And that’s it!

Linux

Tools: Command Line (no clue, your pick)

There are as many flavors of Linux as their are days in the year (I did not confirm if this was true), so I’m not going into all of them here. I could try and include the commands for one of the more popular ones, but that would be opening me up to flaming trolls. Instead, I’ll just link to node’s fantastic guide to installing it via package manager for a bunch of Linux distros.

Go wild:

Installing node.js via package manager

Once the applicable install command has finished, enter the below commands to confirm everything is working as it should:

node --version

npm --version

These should output some version, which doesn’t matter as much as it outputting something. And that’s it!

Upgrading node and npm

Installing node & npm are much easier then upgrading. Well, there was this one time at work that I was trying to upgrade node and deleted my whole installation and I freaked out and so that’s what I’m basing that statement on. In reality, it’s probably not that bad (especially if you follow these instructions).

*Windows users omit the ‘sudo’

sudo npm cache clean -f

sudo npm install -g n

sudo n stable

And that will bring you to the newest version of node!

If there are any inconsistencies with this article, please let me know.


Share this article on → Twitter Facebook Google+ Reddit