hasini galappaththi
Sep 2, 2018 · 2 min read

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

First, you need to install the PPA in order to get access to its contents. Make sure you’re in your home directory, and use curl to retrieve the installation script for your preferred version, making sure to replace 8.x with your preferred version string (if different):

You can inspect the contents of this script with nano (or your preferred text editor):

  • nano nodesource_setup.sh

And run the script under sudo:

  • sudo bash nodesource_setup.sh

The PPA will be added to your configuration and your local package cache will be updated automatically. After running the setup script from nodesource, you can install the Node.js package in the same way you did above:

  • sudo apt-get install nodejs

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

  • nodejs -v
Output
v8.10.0

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade