How to Install Node JS Latest Long-Term Support Version on Ubuntu 22.04?
Node.js is a free, open-source, cross-platform JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.
Node.js is a powerful JavaScript runtime that lets you build scalable and high-performance applications. With the release of Node.js v22, developers now have access to new features, improvements, and bug fixes. This article will guide you step-by-step on how to install Node.js v22 on Ubuntu 22.04.
Step 1: Update Your Package Index
Before installing any packages, it’s important to update your system’s package index. This ensures you’re installing the latest versions available in the repository.
Open your terminal and run the following command:
1 | sudo apt update |
Step 2: Install Required Dependencies
Node.js v22 may require certain dependencies to be installed on your system. Install them using the following command:
1 | sudo apt install curl gnupg2 lsb-release |
These packages are required to download and manage the Node.js installation scripts and repository keys.
Step 3: Add NodeSource Repository
To install the specific version of Node.js (v22), you will need to add the NodeSource repository. NodeSource provides an official repository with pre-built packages for various versions of Node.js.
Run the following command to add the NodeSource repository for Node.js v22:
1 | curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - |
This script will automatically detect your Ubuntu version and configure the repository for Node.js v22.
Step 4: Install Node.js v22
After adding the repository, you can now install Node.js v22. Simply run:
1 | sudo apt install -y nodejs |
This will install Node.js along with the npm (Node Package Manager) that comes bundled with it.
Step 5: Verify the Installation
Once the installation is complete, you can verify that Node.js v22 is installed correctly by checking the version of Node.js and npm.
To check the Node.js version, run:
1 | node -v |
This should return something like:
1 | v22.x.x |
To check the npm version, run:
1 | npm -v |
This will confirm that npm has also been installed successfully.
Step 6: (Optional) Install Build Tools
If you’re planning to build native add-ons or work with some npm packages that require compiling, you may need to install additional build tools:
1 | sudo apt install -y build-essential |
This will install the necessary compilers and libraries for building native modules.
Troubleshooting
- Problem: After installation,
node
ornpm
commands aren’t recognized.- Solution: Make sure that
/usr/local/bin
is in your system’sPATH
. You can check this by runningecho $PATH
and adding the directory if it’s missing.
- Solution: Make sure that
- Problem: Some packages fail to build or install.
- Solution: Installing
build-essential
should resolve most compilation issues.
- Solution: Installing
Conclusion
You’ve successfully installed Node.js v22 on Ubuntu 22.04. Whether you’re developing a new project or maintaining an existing one, Node.js v22 offers the latest features to help you build high-performance applications. If you encounter any issues during the installation, be sure to check the official Node.js documentation or ask the community for help.