Node.js is a powerful, open-source JavaScript runtime environment that allows you to run JavaScript code outside the browser — making it ideal for building fast and scalable web applications. If you’re working on Ubuntu 22.04 dedicated server and want to get started with Node.js, this guide will walk you through the process of installing it step by step.

Method 1: Install Node.js from Ubuntu Repository

This is the simplest method, but it may not provide the latest version.

Step 1: Update Your Package Index

sudo apt update

Step 2: Install Node.js

sudo apt install nodejs -y

Step 3: Install npm (Node Package Manager)

sudo apt install npm -y

Step 4: Verify Installation

node -v
npm -v

If you need the latest version of Node.js, consider the next method using NodeSource.

Method 2: Install Latest Node.js via NodeSource

NodeSource provides up-to-date Node.js packages.

Step 1: Download and Run the NodeSource Script

For example, to install Node.js v20.x:

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

Step 2: Install Node.js

sudo apt install nodejs -y

This will install both node and npm.

Step 3: Verify Installation

node -v
npm -v

Method 3: Install Node.js Using NVM (Node Version Manager)

This method is recommended if you want to manage multiple versions of Node.js.

Step 1: Install NVM

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

Then restart your shell or run:

source ~/.bashrc

Step 2: Install the Latest Node.js Version

nvm install node

Or install a specific version:

nvm install 18.19.0AVA.HOSTING

Step 3: Use a Specific Version

nvm use node

Step 4: Set Default Node Version

nvm alias default node

Conclusion

Installing Node.js on Ubuntu 22.04 is easy, and you have several options depending on your needs:

  • Use the Ubuntu repository for a quick install.

  • Use NodeSource for the latest version.

  • Use NVM to manage multiple versions.

Whichever method you choose, you’ll be ready to start building powerful applications with Node.js in no time.