Skip to content

How to install Node.js and npm to Ubuntu 16.04

Daisho Komiyama edited this page Mar 18, 2019 · 2 revisions

Today I installed Node.js and npm to my nginx server by following this article How to install Node.js

The article shows you a couple of ways to follow. I firstly tried the simplest method using apt-get but it installed v4.2.6 which is way too outdated to use in 2019.

So I tried the second method in the article.

Install using PPA

cd ~

curl -sL https://deb.nodesource.com/setup_9.x -o nodesource_setup.sh

You can inspect the contents of this script with vim:

vim nodesource_setup.sh

And run the script under sudo:

sudo bash nodesource_setup.sh

sudo apt-get install nodejs

To check which version of Node.js you have installed after these initial steps, type:

nodejs -v

Output

v9.11.2

The nodejs package contains the nodejs binary as well as npm, so you don't need to install npm separately.

npm uses a configuration file in your home directory to keep track of updates. It will be created the first time you run npm. Execute this command to verify that npm is installed and to create the configuration file:

npm -v

Output

5.6.0

In order for some npm packages to work (those that require compiling code from source, for example), you will need to install the build-essential package:

sudo apt-get install build-essential

You now have the necessary tools to work with npm packages that require compiling code from source.

Clone this wiki locally