How to install NodeJS on Mac, Linux, and Windows

Installing NodeJS can be a painful and confusing experience. There are official installers, package managers, scripts... Which one should you use?

On UNIX (OS X & Linux)

If you don't already have a version of NodeJS installed, the easiest way to install it is by using the Node Version Manager.

Official instructions are in this page, or execute the following commands in a console:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash

Then, restart your terminal and execute the nvm command. You should see something other than "command not found".

If you don't, run touch ~/.bash_profile and run the install script again:

touch ~/.bash_profile

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash

If that still doesn't fix your problem, then run the following command and restart your terminal:

echo "source ~/.bashrc" >> ~/.bash_profile

Now we're ready to install the latest version of Node using nvm:

nvm install node

If it's the first version of node you install with nvm, it will automatically become the default. If you want to change the default, you can do so by doing nvm alias default 8.5.0, for example.

On Windows

If you only require one version of NodeJS (i.e. you don't need multiple versions for anything), the official installer is the easiest way in Windows.

Once it's installed, you should be able to open up cmd.exe and run the node and npm commands!