How to Install Nodejs on Ubuntu 22.04


Nodejs is a freely available run-time environment. It is primarily based on JavaScript, allowing the developers to use JavaScript for server-side scripting, command line tools, and other application developments. Nodejs is enriched with libraries and frameworks at no cost. With its best performance and productivity, Nodejs is becoming a more popular software nationwide.

This article is aiming to improve your knowledge and skill on how to install Nodejs on Linux distributions including Ubuntu 22.04.

How to Install Node Js on Ubuntu 22.04?

The following step-by-step instruction will assist you in installing the latest version of Nodejs on your Ubuntu 22.04 systems.

Step 1: Set Up the NodeSource Repository

Running the command presented below will set up the repository and enable you to install the newest release of Node.js:

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

Step 2: Install Nodejs via “apt”

Node.js can be executed by running the following command:

sudo apt install nodejs -y

The above screenshot confirms that Nodejs has been successfully installed in your Ubuntu 22.04 machine.

Step 3: Update System Packages

Run the “apt update” command to apply the newly installed packages:

sudo apt update

Step 4: Confirmation

Verify the Node Js in your system by using the command provided below:

node --version

The currently available version of Node Js is v20.4.0, as it can be seen in the output.

Step 5: Test Nodejs

You can start the Node Js by typing the command in the terminal:

node

This command will start the Node Js and enable you to type and run your script.

For example, here is a simple script:

console.log("Welcome to Node.js!!")

After pressing the Enter key, the output “Welcome to Node.js!!” will be displayed.

To exit the Node.js scripting terminal, you can type either “.exit” or press “Ctrl+D”.

.exit

As shown above, the screenshot confirms that Node Js is working properly from the terminal.

How to Uninstall Nodejs from Ubuntu 22.04?

The following two steps will completely remove the Node Js and its associated file from your Ubuntu machine.

Step 1: Remove Nodejs

By running the attached command, the Node.js package and its associated files and dependencies will be removed from your Ubuntu system:

sudo apt purge nodejs -y

Step 2: Remove Files and Dictionaries

The following command will automatically remove files and dependencies that are no longer required on your system:

sudo apt autoremove -y

The above screenshot indicates that the unused and unnecessary files and dictionaries have been removed from your operating system.

Conclusion

Once you have set up the NodeSource Repository, you can easily install the latest version of Node.js on Ubuntu 22.04. To install Node.js, simply run the command “sudo apt install nodejs -y” in the terminal. Node.js is widely used for web development, creating APIs, and building real-time applications. This article provided detailed sequential steps on how to install and run Node.js from the Ubuntu terminal.

 

Print Friendly, PDF & Email
Categories