1. Home
  2. Linux
  3. Ubuntu
  4. Install npm on Ubuntu 16.04

Install npm on Ubuntu 16.04

In this tutorial we will teach you how to install NPM on Ubuntu 16.04.
NPM is a JavaScript package manager which you can use to install, share, and distribute code as well as manage dependencies in your projects. It was made entirely in JavaScript taking inspiration from different projects which are similar. Like PEAR for PHP or CPAN for Perl.
Installing npm on Ubuntu 16.04 is a simple task, follow the steps below and you will have NPM successfully installed on Ubuntu 16.04.

Step 1: Connect via SSH and Upgrade/Update your System.

Connect to your Linux VPS via SSH and update your system software to the latest version available. You can do this by running the command below.

sudo apt-get update && sudo apt-get -y upgrade

 
The upgrade procedure will take anywhere from a few seconds to a few minutes depending on the softwares that have to be updated. After your system is up to date, you can continue with the other steps of this guide.
Now, install ‘Node.js’. The installation of Node.js on Ubuntu 16.04 can be done with a couple of methods:
APT: the default Ubutun package manager
PPA: Personal Package Manager
NVM: Node Version Manager
 

Step 2: Installing Node.js Version – 4.x for Ubuntu 16.04.

Npm is usually bundled with Node.js so, in order to install npm, you have to install Node.js on your Ubuntu VPS. To install Node.js 4.x LTS on Ubuntu 16.04, execute the command below.

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

 

Step 3: Installing Node.js Version – 7.x on Ubuntu 16.04

Alternatively, if you want to install Node.js 7.x on Ubuntu 16.04, this will be the current version of Node.js. Simply execute the following commands.

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

 

Step 4: Verify the npm installation on Ubuntu 16.04.

To confirm whether the installation was successful, you will need to check the version of npm.

npm -v

 
You will receive an output similar to the following one.

# npm -v
4.2.0

 

Step 5: Check the npm Help Documentation

A safe way to begin using npm is to read the npm help page or the npm documentation. To check the npm help page, use the following command.
This is the npm help page.

# npm help
Usage: npm <command>
where <command> is one of:
    access, add-user, adduser, apihelp, author, bin, bugs, c,
    cache, completion, config, ddp, dedupe, deprecate, dist-tag,
    dist-tags, docs, edit, explore, faq, find, find-dupes, get,
    help, help-search, home, i, info, init, install, issues, la,
    link, list, ll, ln, login, logout, ls, outdated, owner,
    pack, ping, prefix, prune, publish, r, rb, rebuild, remove,
    repo, restart, rm, root, run-script, s, se, search, set,
    show, shrinkwrap, star, stars, start, stop, t, tag, team,
    test, tst, un, uninstall, unlink, unpublish, unstar, up,
    update, upgrade, v, version, view, whoami
npm  -h     quick help on
npm -l           display full usage info
npm faq          commonly asked questions
npm help   search for help on
npm help npm     involved overview

 
Specify configs in the ‘ini-formatted’ file.

    /root/.npmrc

 
Alternatively, you can do this on the command line via the below.

npm <command> --key value

 
Config info can be viewed via: npm help config

[email protected] /usr/lib/node_modules/npm <command>

 
This should be everything, you should now have npm installed on your Ubuntu 16.04. You can find the npm documentation at https://docs.npmjs.com/.

Updated on February 2, 2019

Was this article helpful?

Related Articles

Leave a Comment

[apsl-login-lite login_text='Please login with a social account']