Installing Node and NPM on Ubuntu Desktop

In this post I will share how to install Node and NPM.

Note: this post is a part of the series of posts about my experience using Ubuntu Desktop for software development.

 

Nodejs, not Node

Keep in mind that on Ubuntu the name of the Node.js package/executable is nodejs, not node.

 

Installing Node and NPM using Package Manager

The easiest way to install stable versions of Node.js and NPM is using package manager. First. let’s check what versions are available

$ sudo apt-get update
$ apt-cache show nodejs
$ apt-cache show npm

At the time of writing, the current versions of nodejs and npm are 4.2.6 and 3.5.2 respectively.

blog-21-01

 

blog-21-02

If these versions suit your needs – go ahead install the packages with these two commands

$ sudo apt-get install nodejs
$ sudo apt-get install npm

 

Installing Node and NPM from NodeSource

If, on the other hand, you want the latest versions of Node.js v4.x or v6.x – you should install them from NodeSource. Setup scripts and instructions are available here. But in short, you need to run these commands which will install both Node.js and NPM:

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

After that you can check the installed versions

$ nodejs --version
$ npm --version

blog-21-03

At the time of writing, the current versions of nodejs and npm from NodeSource are 6.4.0 and 3.10.3 respectively.

 

Installing Build Tools

To compile and install native addons from npm you also need to install build tools

$ sudo apt-get install -y build-essential

And this is all that you need to do to install the latest Node.js and NPM on Ubuntu Desktop.

 

Additional Useful Tools

The two tools that I really like while developing web applications are HTTPie and http-server.

 

HTTPie

HTTPie is a command line HTTP client (the executable is called simply http, but the package is called httpie) similar to curl but with colorized output. The installation instructions suggest that you preferably install against the latest Python 3.x, but it works, with some limitations, with Python 2.7 as well. Installation is pretty simple:

$ sudo apt-get install -y httpie

After that,  you can see the difference in output between http and curl.

blog-21-04

blog-21-05

 

http-server

http-server is a zero-configuration command line HTTP server. It is very helpful for situation when you want to quickly create client-side code and do not want to write any server-side code. To install it globally run the following command

$ sudo npm install http-server -g

Then, suppose you have your web site in ~/src/hello directory, just type hs or http-server to start the HTTP server.

blog-21-06

blog-21-07

blog-21-08

blog-21-09

 

Reference

Installing Node and NPM on Ubuntu Desktop

2 thoughts on “Installing Node and NPM on Ubuntu Desktop

Comments are closed.