How To Install Node.js on Ubuntu 22.04

Introduction

Node.js is a powerful runtime environment that allows developers to run JavaScript on the server-side. With its extensive package ecosystem, it has become a popular choice for building scalable and efficient web applications. If you’re an Ubuntu 22.04 user looking to install Node.js, this article will guide you through the process step by step.

Step 1: Update System Packages

Before installing any new software, it is essential to update the system packages to their latest versions. Open a terminal and execute the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install Node.js using NVM (Node Version Manager)

NVM allows you to install and manage multiple versions of Node.js effortlessly. To install NVM, run the following commands:

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

After the installation completes, close and reopen the terminal, or run the following command to load NVM without restarting:

source ~/.bashrc

Step 3: Verify NVM Installation

To ensure NVM is installed correctly, execute the following command:

nvm --version

This command should display the version of NVM installed on your system.

Step 4: Install Node.js using NVM

Now that NVM is ready, you can install Node.js. Run the following command to list the available Node.js versions:

nvm ls-remote

This command will display a list of Node.js versions. Choose the desired version you want to install, and execute the following command, replacing <version> with the desired version number:

nvm install <version>

For example, to install Node.js version 14, run:

nvm install 14

Step 5: Verify Node.js Installation

To confirm that Node.js has been successfully installed, use the following command:

node --version

This will display the version of Node.js installed on your system.

Step 6: Set Default Node.js Version (Optional)

If you have installed multiple versions of Node.js using NVM and want to set a default version, you can use the following command:

nvm alias default <version>

Replace <version> with the desired Node.js version number. For example:

nvm alias default 14

Step 7: Install npm (Node Package Manager)

npm comes bundled with Node.js and is used to manage JavaScript packages. To verify that npm is installed, run the following command:

npm --version

This will display the version of npm installed on your system.

Conclusion:

Congratulations! You have successfully installed Node.js on Ubuntu 22.04 using NVM. You can now start building powerful web applications using the extensive Node.js ecosystem. Remember to keep your Node.js installation up to date and utilize the power of npm to enhance your development workflow. Happy coding!


Leave a Reply

Your email address will not be published. Required fields are marked *