For enquiries call:

Phone

+1-469-442-0620

April flash sale-mobile

HomeBlogWeb DevelopmentHow to Install Node.JS on Ubuntu [Step-by-Step] for Beginners

How to Install Node.JS on Ubuntu [Step-by-Step] for Beginners

Published
24th Jan, 2024
Views
view count loader
Read it in
9 Mins
In this article
    How to Install Node.JS on Ubuntu [Step-by-Step] for Beginners

    Being able to install Node.js on Ubuntu or another OS is a boon for JavaScript users worldwide. If you're into JavaScript like me, installing Node.js on Ubuntu or any other operating system is a great idea. It's like having one language for all your development tasks. Before Node.js, the JavaScript folks were compelled to learn a second language that helped them perform all their backend activities, a pain in the neck. In this article, I will help you learn step-by-step how to install Node.js on Ubuntu 22.04 (Linux-based) system. Check Node.js Certification to speed up your learning curve. . 

    What is Node.js?

    I used to think Node.js was a programming language, like many newcomers do, but it's actually not. Instead, it serves as an open-source JavaScript runtime environment, allowing the execution of JavaScript code outside the confines of a web browser. Essentially, what Node.js does is take the functionalities and features of the JavaScript language and package them into modules. It takes JavaScript, originally designed to run in a browser, and upgrades it to run in other environments. It's a versatile tool that expands the possibilities of what you can achieve with JavaScript beyond the traditional browser setting.

    Because these upgrades are packaged into Node.js developers can now use JavaScript for frontend and backend development making JavaScript a full-stack language. 

    In the past, Node.js was only designed to serve real-time performance and push-back architectures. Since then, Node.js has developed into a crucial component of server-side scripting for event-driven, non-blocking servers. Today, Node.js powers most traditional websites and API services. Node.js uses an event-driven, non-blocking I/O architecture and the V8 JavaScript runtime engine as its primary power source. 

    Who Uses Node.js

    Millions of websites all around the world use Node.js. It has millions of downloads as can be seen by its weekly npm installations.  

    JavaScript full-stack developers enjoy the comfort Node.js brings to the technology space. This is because Node.js enhances the performance of developers and facilitates the development process. 

    Top companies that use Node.js include: 

    • NASA 
    • Twitter 
    • Netflix 
    • LinkedIn 
    • PayPal 
    • GitHub 
    • eBay 
    • Walmart 
    • Spotify 
    • Medium 

    If you research these companies, you will notice that they base their companies' operations on numerous services or goods. However, they all share a vital characteristic which is that they all rely on Node.js. No matter what business you're in, employing Node.js can solve most of your development problems. 

    Prerequisites

    Before installing the updated node version on ubuntu, you must ensure that you’ve accumulated all the necessary knowledge. Also, make sure you’ve downloaded all required installation files and elements. 

    First, it would help a lot if you had a basic understanding of JavaScript and its syntax. This enables you to pick up Node.js easily. 

    Secondly, you may work on server-side coding by having a basic grasp of an object-oriented programming (OOP) language. 

    1. Hardware Requirements 

    Below are the hardware requirements for installing Node.js on Ubuntu. 

    • Node.js does not need a complex hardware configuration to work; most machines nowadays are compatible. 
    • Node.js installation requires a stable hard drive for it to work. 
    • You should have the necessary prerequisites to install Node.js on Ubuntu.  
    • Virtually all modem computers can run Node.Js, including miniature computers like BeagleBone or Arduino YÚN. 
    • The Random-Access Memory (RAM) of your system should be up to 4GB and your system storage should be at least 256GB of Hard Disk Space. 

    2. Software Requirements

    • Below are the software requirements for installing Node.js on Ubuntu. The web browser should be intact. Any browser such as Google Chrome, Mozilla Firefox, or Microsoft Edge can run Node.js. 
    • Operating System should be accurate and free, having an Ubuntu server installed with a non-root Sudo user and firewall. 

    How to Install Node.js on Ubuntu [Step-by-Step]

    Let me take you through the three methods below to install Node.js on your Ubuntu machine.

    Method 1: Installing the Stable Version for Ubuntu 

    Before you can install a stable version of Node.js for Ubuntu, you must update the terminal first. 

    Step 1:You can use the apt package manager to obtain the version that can run Node.js. Update the index for your regional package usage. 

    $ sudo apt update 

    How to Install Node.js on Ubuntu

    Step 2: Install Node.js from the repository in step two. 

    $ sudo apt install Node.js 

    How to Install Node.js on Ubuntu

    Step 3:Install npm ubuntu with the code below. 

    $ sudo apt install npm 

    How to Install Node.js on Ubuntu

    Step 4:Use this to check which Node.js version you installed. 

    $ Node.js -v && npm --version 

    And there you have it for this method. If you want to upgrade your JavaScript skills, visit the Full Stack Developer course to enhance your development skill. 

    Method 2: Install Node.js Using a PPA 

    Software repositories of various packages specifically created for Ubuntu 20.14 users are included in the PPA repository. The PPA repository for the most recent Node.js version is added first. 

    Before installing Node.js using PPA, ensure that you have the curl command-line utility installed on your system. If curl isn’t installed on your system paste this command on your terminal to install curl:  

    $ sudo apt install curl 

    How to Install Node.js on Ubuntu

    After installing curl add the Node.js source with the following code. 

    $ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

    How to Install Node.js on Ubuntu

    If you experience an issue with the public such as “the following signatures couldn’t be verified because the public key is not available” 

    Now, on the console, you should see the public key; copy it, replace it in the <PUBLIC KEY> space below, and run it on the terminal. 

    $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <PUBLIC KEY> 

    Now run the command below to install Node.js npm Ubuntu 20.04 on your machine. 

    $ sudo apt-get install -y Node.js 

    If you’ve done everything correctly, Node.js will successfully install on your Linux distribution. To check node version Ubuntu, run the command shown below and the newest version is installed. 

    node -v && npm --version

    How to Install Node.js on Ubuntu

    Method 3: Install Node.js Using NVM

    The NVM (Node Version Manager) is also used to install Node.js. It has the advantage of displaying a list of all available Node.js versions, from which you can choose to either install the most recent version or a specific version. Use the instruction below to install Node.js ubuntu command line. 

    $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash 

    How to Install Node.js on Ubuntu

    Now install the latest Node.js on NVM using the command below. 

    $ nvm install node 

    How to Install Node.js on Ubuntu

    With the above, you will install node and npm on Ubuntu. 

    How to Verify the Installation 

    Now you’ve installed Node.js, you can verify the installation to check if the installation was successful. To confirm the installation, you must run the following Linux commands on your terminal. 

    To check the Node.js version type: 

    $ node -version  

    And to check the npm version, type: 

    $ npm --version 

    The Node.js and npm version names should be displayed on the terminal if they were successfully installed. 

    Create Demo Web Server

    Step 1: Open a code editor and select a working directory. 

    Step 2: Create a new file called index.js in the root of the working directory. 

    Step 3:Copy and paste the codes below inside the index.js file. 

    const express = require('express'); 
    const app = express(); 
    [Text Wrapping Break] 
    app.get('/', function (req, res) { 
      res.send('Hello World!'); 
    }); 
    app.listen(3000, function () { 
      console.log('Example app listening on port 3000!'); 
    }); 
     

    Step 4:Now run the server with the code below on your terminal. 

    $ node index.js 

    The result will appear as an example app running on port 3000. 

    Step 5: Visit http://127.0.0.1:3000/ on the browser to see this page. 

    And that’s how you create a web server with Node.js. 

    How to Use the Node.js on Ubuntu 

    Using Node.js on Ubuntu is simple, just as you would use it on other operating systems. 

    Step 1: Create a file called index.js in the root of your working directory. 

    Step 2: For this example, let’s create a simple function that adds two values together. Copy and paste the code below into your index.js file. 

    function add(y,z) { 
      return y+z; 
    } 
    console.log(add(81, 9)) 

    Step 3: Execute the code by running $ node index.js on the terminal which would result in the output below: 

    // 90 

    How to Uninstall Node.js from Ubuntu? 

    The following instructions remove Node.js from your Ubuntu system.  

    $ sudo apt remove Node.js 
    $ sudo apt purge Node.js -y 

    Uninstall Using NVM 

    First, check to see if it is the most recent active version. 

    $ nvm current 

    Now deactivate the version using the command below. 

    $ nvm deactivate 

    How to Install Node.js on Ubuntu

    The above command removes NVM from Ubuntu. 

    Advantages of Using Node.js

    The correct programming platform for your tech stack is just as crucial as the amount of labor you wish to commit to it. When determining the benefits of utilizing a specific platform, a variety of criteria should be considered. The total benefit distribution may be changed by factors including the learning curve, the rate of development, the community, and scalability. 

    The following are the key benefits of utilizing Node.js: 

    • Easy syntax 
    • Easy to learn new skills 
    • Quick scaling ability 
    • Flexible and open source 
    • Cross-platform programming 
    • Full-stack single-language development 
    • Instantaneous communication 
    • A sizable and vibrant community

    Looking to unlock the power of coding? Join our python programming classes and embark on a journey of endless possibilities. Discover the unique and versatile world of Python today!

    Conclusion

    To sum it up, learning to install Node.js on Ubuntu is a great thing for JavaScript fans like me. It means you can use one language for both frontend and backend tasks, making things simpler. Whether you go for the stable version, a PPA, or use NVM, the installation is pretty straightforward. Node.js is a big deal, used by major companies, and it makes coding more flexible and efficient. With its easy-to-understand syntax and a helpful community, Node.js is a powerful tool for building all sorts of applications. Once you have Node.js, there's a whole world of coding possibilities waiting for you!

    If you want to improve your web development ability, kindly check KnowledgeHut’s Node.js Certification.

    Frequently Asked Questions (FAQs)

    1Can Node.js run on Ubuntu?

    Node.js can be installed on a variety of operating systems, including Windows, macOS, and Linux-based systems such as Ubuntu.

    2What is the latest version of node JS for Ubuntu?

    As of the time of writing this tutorial, Node.js is at an LTS version of 16.17.0 and a current version: 18.8.0. The LTS is the most stable version while the current version is always loaded with the latest features.

    3How do I know if node.js is installed?

    To check if Node.js is installed on your Ubuntu system, all you need to do is to simply node -v and that will display the currently installed version of Node.js.

    4How do I change the Node.js version in Ubuntu?

    NVM is recommended for quickly switching different versions of Node.js on your machine by executing the command below. 

    nvm use <specify version>

    Profile

    Darlington Gospel

    Blog Author

    I am a Software Engineer skilled in JavaScript and Blockchain development. You can reach me on LinkedIn, Facebook, Github, or on my website.

    Share This Article
    Ready to Master the Skills that Drive Your Career?

    Avail your free 1:1 mentorship session.

    Select
    Your Message (Optional)

    Upcoming Web Development Batches & Dates

    NameDateFeeKnow more
    Course advisor icon
    Course Advisor
    Whatsapp/Chat icon