How to Install NodeJS on Ubuntu / Debian / Linux Mint using PPA

ADVERTISEMENT

Install NodeJS on Ubuntu / Debian / Linux Mint
Install NodeJS on Ubuntu / Debian / Linux Mint

Node.js is an open source, cross-platform JavaScript runtime environment for developing network tools and web applications. Many of Node.ja modules are written in JavaScript, which simplifies development of applications using Node.js. Node.js nothing but a combination of Runtime environment and JavaScript modules.

Node.js interprets JavaScript using Google’s V8 JavaScript engine; it was developed by Ryan Dahl in 2009. This guide helps you to install Node.js on Ubuntu / Debian / Linux Mint operating systems.

ADVERTISEMENT
Article will continue after the ad

Versions:

The are two versions of Node.js is available for the users. Check out the official page to get the latest version of Node.js.

  • v4.5.0, Long Term Supported
  • v6.5.0, Current Latest Version

Supported Operating Systems:

Ubuntu versions:

  • Ubuntu 12.04 LTS (Precise Pangolin)
  • Ubuntu 14.04 LTS (Trusty Tahr)
  • Ubuntu 16.04 LTS (Xenial Xerus)

Debian versions:

  • Debian 7 (wheezy)
  • Debian 8 / stable (Jessie)

Linux Mint versions:

  • Linux Mint 13
  • Linux Mint 17
  • Linux Mint 17.1
  • Linux Mint 17.2
  • Linux Mint Debian Edition (LMDE) 2

Install Build Toos:

This step is optional: You may need to install build tools If you want to compile and install native add-ons from npm.

$ sudo apt-get install -y build-essential

Add Node.js PPA:

Node.js binary packages are maintained by NodeSource Debian and Ubuntu binary distributions repository (formerly Chris Lea’s Launchpad PPA). You can choose either one of the Node.js version to install on your machine.

### PPA for Node.js v4.5.0 ###

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -

### PPA for Node.js v6.5.0 ###

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
If you are planning to install Node.js v4.x on Ubuntu 12.04 or Debian 7, consider reading about running Node.js 4.x on older distros.

Install Node.js:

Once after adding the PPA on the server, install the Node.js by using the following command. NPM (Node Package Manager) will also be installed along with Node.js.

$ sudo apt-get install -y nodejs

Verify Node.js Installation:

Check the version of Node.js and NPM using the following command. The following output is for your informational, and it depends on the repository (v4.x or v6.x) you chose to install.

$ nodejs -v
v6.5.0

$ npm -v
3.10.3

Create Test Web Server:

If you want to test your Node.js installation, create a web server and run with Node.js.

 

Let’s create a file called “web_server.js

$ vi web_server.js

Place the below content into the web_server.js file.

const http = require('http');
const port = 8080;
const server = http.createServer((req, res) => {
   res.writeHead(200, {'Content-Type': 'text/plain'});
   res.end('Hello World\n');
});
server.listen(port, () => {
  console.log(`Server running at http://your-ip-add-ress:${port}/`);
});

Now, start the web server using the below command.

$ nodejs --debug web_server.js

You should get the following message on your terminal. This confirms the web server has been started and listening on port 8080.

Open your web browser and navigate it to the following web address.

http://your-ip-add-ress:8080

You should get the web page like below.

Install NodeJS on Ubuntu using PPA
Install NodeJS on Ubuntu using PPA

That’s all. You have successfully installed Node.js on Ubuntu / Debian / Linux Mint.

ADVERTISEMENT

POSTS YOU MAY LIKE -:)

Share This Post

Shares