For enquiries call:
+1-469-442-0620
HomeBlogWeb DevelopmentHow 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. .
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.
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:
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.
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.
Below are the hardware requirements for installing Node.js on Ubuntu.
Let me take you through the three methods below to install Node.js on your Ubuntu machine.
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
Step 2: Install Node.js from the repository in step two.
$ sudo apt install Node.js
Step 3: Install npm ubuntu with the code below.
$ sudo apt install npm
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.
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
After installing curl add the Node.js source with the following code.
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
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
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
Now install the latest Node.js on NVM using the command below.
$ nvm install node
With the above, you will install node and npm on Ubuntu.
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.
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.
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
The following instructions remove Node.js from your Ubuntu system.
$ sudo apt remove Node.js $ sudo apt purge Node.js -y
First, check to see if it is the most recent active version.
$ nvm current
Now deactivate the version using the command below.
$ nvm deactivate
The above command removes NVM from Ubuntu.
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:
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!
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.
Node.js can be installed on a variety of operating systems, including Windows, macOS, and Linux-based systems such as 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.
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.
NVM is recommended for quickly switching different versions of Node.js on your machine by executing the command below.
nvm use <specify version>
Name | Date | Fee | Know more |
---|