If you’ve been exploring the world of front-end and JavaScript, you might have come across Node.js. It is a server-side framework that uses Google’s V8 engine to execute JavaScript code. Developers can use Node.js as it provides them with an easy way to build fast and scalable network applications, using single-threaded asynchronous events.

Advertisement

In this article, we will see how to install Node.js on Ubuntu and its derivatives via a new official PPA repository. If you are new to Ubuntu or any other Linux operating system, then be sure to check out our beginner’s guide first.

You can also use the popular Node Version Manager (NVM) for installing specific Node.js version on your system.

Step 1 – Configuring Node.Js PPA

Node.js releases are available in two types, one is the LTS release, and the other is the current release. Choose any one version of your choice or as per the project requirements. Let’s add the PPA to your system to install Nodejs on Ubuntu.

  • Use Current Release –
  • During the last update of this tutorial, Node.js 19 is the current Node.js version available.
sudo apt install -y curl 
curl -sL https://deb.nodesource.com/setup_19.x | sudo -E bash - 

  • Use LTS Release – Instead of the current release, it’s a good idea to use a stable version. During the last update of this tutorial, Node.js 18 is the latest LTS release available.
    sudo apt install -y curl 
    curl -sL https://deb.nodesource.com/setup_18.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 have successfully configured Node.js PPA in your Ubuntu system. Now execute the below command to install Node on 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 install -y nodejs 
    

    That’s it. This will install Node.js on your Ubuntu system.

    Step 3 – Check Node.js and NPM Version

    After installing node.js verify and check the installed version. You can find more details about the current version on node.js official website.

    node -v
    
    v19.2.0
    

    Also, check the npm version

    npm -v 
    
    8.19.3
    

    Step 4 – Create Demo Web Server (Optional)

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

    sudo nano 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/');

    Save the file and close. Then start the Node application using the following command.

    node server.js 
    
    debugger listening on port 5858
    Server running at 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
    Server running at http://127.0.0.1:3000/
    

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

    Conclusion

    In conclusion, we have seen how to install Node.js on Ubuntu and its derivatives via a new official PPA repository. This makes it easy for us to get started with Node.js development on our Linux systems. We can also use this repository to keep our installations up-to-date with the latest stable versions of Node.js. Be sure to check out other tutorials on our website for more tips and tricks about using Node.js!

    Share.

    55 Comments

    1. Akshay Sunil Mehta on

      W: GPG error: http://dl.google.com/linux/chrome/deb stable InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 78BD65473CB3BD13
      E: The repository ‘http://dl.google.com/linux/chrome/deb stable InRelease’ is not signed.
      N: Updating from such a repository can’t be done securely, and is therefore disabled by default.
      N: See apt-secure(8) manpage for repository creation and user configuration details.

      I’m getting these error while adding nodejs ppa

    2. Muhammad Ahsan on

      E: coult not get lock /var /lib/dpkg/lock-fronted -open
      this error shows when i enters te command

    3. soujanya duvvi on

      http://archive.ubuntu.com/ubuntu yakkety InRelease
      Could not connect to 125.200.13.2:80 (125.200.13.2). – connect (111: Connection refused)

      this is the error i’m getting while installing ppa

      even sudo apt-get update is also throwing the same error
      What can i do please do reply

    4. Maxim Cournoyer on

      On Ubuntu 18.04 server, I had to use ‘software-properties-common’ instead of ‘python-software-properties’:

      virtualbox-iso: Package python-software-properties is not available, but is referred to by another package.
      virtualbox-iso: This may mean that the package is missing, has been obsoleted, or
      virtualbox-iso: is only available from another source
      virtualbox-iso: However the following packages replace it:
      virtualbox-iso: software-properties-common
      virtualbox-iso:
      virtualbox-iso: E: Package ‘python-software-properties’ has no installation candidate

    5. node -v tells me node is not installed. Installing node-legacy puts down a symlink so that node -v works.

      However it returns v4.7.2.

      Ubuntu 17.04.

      Turns out my apt sources.list had a site which couldn’t be reached, so the PPA wasn’t being added, so it was just installing the distro version. With that fixed nodejs -v returns v8.9.1. nodejs-legacy won’t install though. I’ll just make the symlink myself.

    6. How set for custom domain on ubuntu ?

      var http = require(‘http’);
      http.createServer(function (req, res) {
      res.writeHead(200, {‘Content-Type’: ‘text/plain’});
      res.end(‘Hello World\n’);
      }).listen(80, “customdomain.com”);
      console.log(‘Server running at http://customdomain.com:80/‘);

    7. I have tried installing nodejs 8 , but my system always installs 4.2.6 version.Am using ubuntu 16.04.
      How can i solve this?Thanks

      • Make sure that Curl is installed on your system, pull the repo, it should usually update your repos automatically, then you can run ‘sudo apt-get install nodejs’ to get the latest version

    8. node -v _does not display the version_, it prompts you to install nodelegacy.

      To view the node_js_ version, you run _nodejs -v_

      sudo apt-get install nodejs *does not install npm, you need to install it manually*

    9. Did you do sudo before running this command? The previous command uses sudo which is carried forward here too. If you took a long time to run the second command, the sudo will need to be revoked again.

      Simply follow the entire tutorial again but a bit faster this time.

    10. Brandon Authier on

      Small typo in the node.js code:

      res.end(‘Hello Worldn’);

      Should be:

      res.end(‘Hello World\n’);

      just a simple fix by adding the forward slash.

    Exit mobile version