How to Install Node.js on Ubuntu 22.04 Server
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 updateStep 2: Install Node.js
sudo apt install nodejs -yStep 3: Install npm (Node Package Manager)
sudo apt install npm -yStep 4: Verify Installation
node -v
npm -vIf 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 -yThis will install both
nodeand
npm.
Step 3: Verify Installation
node -v
npm -vMethod 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 | bashThen restart your shell or run:
source ~/.bashrcStep 2: Install the Latest Node.js Version
nvm install nodeOr install a specific version:
nvm install 18.19.0AVA.HOSTINGStep 3: Use a Specific Version
nvm use nodeStep 4: Set Default Node Version
nvm alias default nodeConclusion
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.


