How To Install Node.js on Ubuntu

Spread the love

Installing Node.js on Ubuntu 22.04: A Comprehensive Guide

Introduction to Node.js

Node.js is a powerful JavaScript runtime that lets developers create scalable, high-performance applications. It implements an event-driven, non-blocking I/O model, making it ideal for developing real-time applications such as web servers and APIs. In this guide, we will walk you through the process of installing Node.js on Ubuntu 22.04, using various methods to suit your requirements.

Our guide will not only walk you through the installation process, but also provide you with insights into various installation methods. Whether you use the default Ubuntu repositories for simplicity, the NodeSource repository for specific Node.js versions, or the flexibility of Node Version Manager (NVM) for managing multiple versions, you will gain a thorough understanding of how to maximize the potential of Node.js on Ubuntu 22.04.



Prerequisites

Before we begin, ensure you have the following prerequisites:

  • An Ubuntu 22.04 server with sudo privileges.
  • Access to a terminal or command-line interface.

Option 1: Using Default Ubuntu Repositories

The default repository’s packages are officially maintained, tested, and supported by the Ubuntu development team. This ensures the reliability and security of the software in this repository. The repository contains a large collection of open-source software, such as applications, libraries, and developer tools.

Update Package List:

sudo apt update

Install Node.js and npm:

sudo apt install nodejs npm

Verify Installation:

node -v

npm -v

Option 2: Using NodeSource Repository

The NodeSource repository provides a variety of Node.js versions, allowing users to select the version that best meets their application’s requirements. This flexibility is critical for developers who may need to work with a specific Node.js version for their projects.

Install Dependencies:

sudo apt install curl

Add NodeSource Repository:

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

Replace “18.x” with your desired Node.js version.

Install Node.js and npm:

sudo apt install nodejs

Verify Installation:

node -v

npm -v

Option 3: Using NVM (Node Version Manager)

NVM, or Node Version Manager, is a command-line tool that enables developers to manage multiple Node.js versions on the same machine. It provides a convenient way to install, switch between, and manage different Node.js versions, catering to the diverse needs of various projects.

Install NVM:

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

Close and reopen your terminal or run source ~/.bashrc to apply changes.

Install Node.js (example with version 18):

nvm install 18

Set Default Node.js Version:

nvm alias default 18

Verify Installation:

node -vnpm -v

Conclusion

Installing Node.js on Ubuntu 22.04 is a crucial step for developing and running JavaScript applications. Depending on your requirements, you can choose the method that best suits your needs. Whether you opt for the default Ubuntu repositories, NodeSource repository for specific versions, or NVM for managing multiple versions, each approach provides flexibility and control over your Node.js environment. You can read this also How to create simple react app.

Now that you have Node.js installed, you’re ready to embark on a journey of building powerful and scalable applications using this versatile JavaScript runtime. Happy coding!

See also  Browsing linux filesystem

Leave a Comment

PHP Code Snippets Powered By : XYZScripts.com