Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»Nodejs»How to Install Latest Node.js on Ubuntu

    How to Install Latest Node.js on Ubuntu

    By RahulDecember 15, 20223 Mins Read

    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!

    node node.js NodeJs npm Ubuntu
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Error: EACCES: permission denied, scandir (Resolved)

    How to Create React.js Application on macOS

    How to list all collections in MongoDB database

    View 55 Comments

    55 Comments

    1. RTFM on November 26, 2022 10:34 am

      “It is a server-side framework” – NO IT’S NOT

      Reply
    2. Robert Lewandowski on August 4, 2022 6:04 am

      Thanks

      Reply
    3. Akshay Sunil Mehta on June 2, 2020 12:07 pm

      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

      Reply
      • Rahul on August 17, 2021 2:10 am

        Removed broken chrome PPA or try below tutorial to fix error:

        https://tecadmin.net/expired-key-expkeysig-with-apt/

        Reply
    4. Yurist-bek on March 16, 2020 6:47 am

      Illegal instruction] – rollbackFailedOptional: verb npm-session xxxxxxxxxxxxxxxxx

      Reply
    5. brhr on December 17, 2019 4:06 pm

      top question: how to exit vim?)

      Reply
      • Rahul on December 19, 2019 8:48 am

        Press escape (Esc) to open command mode in vim and then type :wq and press enter.

        Reply
    6. aleksb86 on December 10, 2019 2:09 pm

      Thanks! Its so helpful

      Reply
    7. Joyce on November 22, 2019 2:17 am

      Thank you very very much! I was lost…

      Reply
    8. Dennis G Daniels on October 31, 2019 5:33 pm

      Very helpful! Thank you!

      Reply
    9. rudra on September 30, 2019 10:42 am

      [email protected]:~$ node –inspect server.js
      Debugger listening on ws://127.0.0.1:9229/fd423a7e-c779-44d0-ac4f-312873eb4482
      For help, see: https://nodejs.org/en/docs/inspector
      Server running at http://127.0.0.1:3000/
      events.js:186
      throw er; // Unhandled ‘error’ event
      ^

      Error: listen EADDRINUSE: address already in use 127.0.0.1:3000

      Reply
      • Rahul on September 30, 2019 12:45 pm

        It looks some other application is already running on port 3000. To find out process run below command:

        netstat -tulpn | grep 3000

        Reply
    10. armel sanou on August 2, 2019 12:16 pm

      Thanks for this tutorial all works correctly for me.
      I used Ubuntu 18

      Reply
    11. jrg_300i on July 20, 2019 7:00 pm

      muchas gracias, funciona bien ! saludos from venezuela

      Reply
    12. Rishi on July 5, 2019 2:01 pm

      Thanks worked perfectly on ubuntu 14

      Reply
    13. thiago on June 29, 2019 8:28 pm

      only download the v8, not the lts

      Reply
    14. Muhammad Ahsan on June 21, 2019 7:08 am

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

      Reply
    15. soujanya duvvi on June 11, 2019 1:09 pm

      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

      Reply
    16. Seetesh Hindlekar on April 23, 2019 7:50 am

      On certain servers, port 3000 too needs to be opened by using the ufw command

      Reply
    17. Daniel on March 29, 2019 11:30 am

      Thank you for the post.

      Reply
    18. Troy on March 21, 2019 12:44 am

      Thanks! worked perfectly

      Reply
    19. Elionai Figueiredo on January 3, 2019 10:25 pm

      Thanks …show de Bola @@@.

      Reply
    20. RaZesh on December 19, 2018 4:11 pm

      Thank you man….

      Reply
    21. Jai Rana on September 3, 2018 1:18 am

      Thanks man, I always use this code to install nodejs. Thanks again..

      Reply
    22. Maxim Cournoyer on May 29, 2018 1:12 pm

      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

      Reply
      • reynaldo1x on September 1, 2018 3:35 pm

        it’s correct!. You need to use ‘software-properties-common’ instead of ‘python-software-properties’.

        Reply
    23. Osi on April 26, 2018 5:11 am

      Hello, Thanks for the info.
      Whenever I run curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -, or any version, I get this response – “bash: curl: command not found.” What seems to be the problem?

      Reply
      • Rahul K. on April 26, 2018 10:28 am

        Run below commands first:

        sudo apt-get install curl

        Reply
        • Osi on April 26, 2018 2:45 pm

          It was installed. Thank you so much!

          Reply
    24. Jeff Van Epps on November 12, 2017 2:17 pm

      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.

      Reply
      • Edgar on June 1, 2018 4:31 am

        Thanks Jeff! You help me very much!

        Reply
    25. Ashik on September 28, 2017 6:47 am

      thanks

      Reply
    26. hosein on September 22, 2017 9:52 am

      hi how remo this??

      Reply
    27. Din on August 14, 2017 9:43 am

      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/‘);

      Reply
      • Rahul K. on August 14, 2017 9:49 am

        Hi Din,

        You need to setup Nginx or Apache as a reverse proxy server in front of Nodejs.
        https://tecadmin.net/setup-nginx-as-frontend-server-for-nodejs/

        Reply
        • Din on August 14, 2017 9:57 am

          Thanks

          Reply
    28. WebDev on August 9, 2017 7:25 am

      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

      Reply
      • Abdel on August 9, 2017 10:54 am

        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

        Reply
        • reza on May 24, 2018 4:29 am

          hi
          I have same problem and can’t resolve that.if you can please help me.

          Reply
    29. Vivek Singh on July 17, 2017 3:30 pm

      How can I stop the server? Thanks in advance!

      Reply
    30. Rahul Kumar on June 14, 2017 8:02 am

      Small error in code “}).listen(3001, “127.0.0.1”);” listen port should be 3000.

      Reply
      • Rahul K. on June 15, 2017 5:17 am

        Thank you very much. Article updated.

        Reply
    31. sowrong on June 7, 2017 4:05 am

      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*

      Reply
      • Rahul K. on June 8, 2017 7:52 am

        Which OS and version are you using?

        Reply
    32. Muhammad on May 29, 2017 5:54 pm

      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.

      Reply
    33. Akash Kanodia on April 11, 2017 5:15 am

      Thank you. Your article was helpful.

      Reply
    34. NAVEEN RAJU on March 19, 2017 5:39 am

      Great article, quite helpful

      Reply
    35. Piyush on December 12, 2016 11:44 am

      Thanks for sharing.. learning lot of things

      Reply
    36. Brandon Authier on December 10, 2016 10:48 pm

      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.

      Reply
      • Rahul K. on December 20, 2016 7:00 am

        Thanks Brandon,

        Tutorial has been updated.

        Reply
    37. Shubhabrata Naha on October 1, 2016 9:47 am

      The last command is wrong : it should be

      nodejs –debug http_server.js

      for version : nodejs -v

      Reply
      • Miguel Lapizco on December 12, 2016 6:11 pm

        Thanks that worked for me.

        Reply
      • Josh on February 1, 2017 9:44 pm

        Thank you!!

        Reply
    38. Ayushman on May 20, 2016 5:57 pm

      Thanks admin… works perfectly on Ubuntu 16.04

      Reply
    39. edgar on April 15, 2015 2:05 pm

      Thanks work great for me thank you !

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.