How do I install NodeJS in Ubuntu ?
Tags: ubuntu, node, javascript
Published: 2021-02-24 08:49:56


Quick instructions on how to install NodeJS in Ubuntu Linux …


**Step 1: **add this PPA to your Ubuntu 20.04 LTS, 19.10, 18.04 LTS, 16.04 LTS (Trusty Tahr) and 14.04 LTS (Xenial Xerus) systems and install node.js on Linux VPS with easy commands.

Node.js package is available in the LTS release and the current release. Select which version you wish to install on your machine according to your needs. Then add the PPA to your system in order to install Nodejs on Ubuntu.

Use Current Release — During the last update of this tutorial, Node.js 15.8.0 is the current Node.js release available.

    sudo apt-get install curl
    curl -sL [https://deb.nodesource.com/setup_15.x](https://deb.nodesource.com/setup_15.x) | sudo -E bash -

Use LTS Release — Instead of current release, its good idea to use stable version. During the last update of this tutorial, Node.js 14.x LTS release available.

    sudo apt-get install curl
    curl -sL [https://deb.nodesource.com/setup_14.x](https://deb.nodesource.com/setup_14.x) | sudo -E bash -

For this tutorial, I am using the latest current release and added their PPA to my system.

## Step 2 — Install Node.js on Ubuntu

You can successfully add Node.js PPA to the Ubuntu system. Now execute the below command install Node on and Ubuntu using apt-get. This will also install NPM with node.js. This command also installs many other dependent packages on your system.

    sudo apt-get install nodejs

## Step 3 — Check Node.js and NPM Version

After installing node.js verify and check the installed version. You can find more details about current version on node.js [official website](https://nodejs.org/download/).

    node -v 

    v15.8.0

Also, check the npm version

    npm -v 

    7.4.0

## Step 4 — Create Demo Web Server (Optional)

This is an optional step. If you want to test your node.js install. Let’s create a web server with “Hello World!” text. Create a file server.js

    vim server.js

and add the following content

server.js

    var http = require('http');
    http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
    }).listen(3000, "127.0.0.1");
    console.log('Server running at [http://127.0.0.1:3000/');](http://127.0.0.1:3000/');)

Now start the Node application using the command.

    node server.js

    debugger listening on port 5858
    Server running at [http://127.0.0.1:3000/](http://127.0.0.1:3000/)

You can also start the application with debugging enabled with the following commands.

    node --inspect server.js

    Debugger listening on ws://127.0.0.1:9229/938cf97a-a9e6-4672-922d-a22479ce4e29
    For help, see: [https://nodejs.org/en/docs/inspector](https://nodejs.org/en/docs/inspector)
    Server running at [http://127.0.0.1:3000/](http://127.0.0.1:3000/)

The web server has been started on port 3000. Now access [http://127.0.0.1:3000/](http://127.0.0.1:3000/) URL in browser. Now you will need to configure a front-end server for your app.


**Additional Resources to learn NodeJS:**

[Introduction to NodeJS Learn and Understand JavaScript](https://coursesim.com/course/introduction-to-nodejs-learn-and-understand-javascript/)

[NodeJS — The Complete Guide (MVC, REST APIs, GraphQL, Deno)](https://click.linksynergy.com/deeplink?id=NcMZU1aTATA&mid=39197&murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Fnodejs-the-complete-guide%2F)