In two previous articles we demonstrated how to install nodejs on Debian 11 and also the steps to install Nodejs on a cPanel server.
As the Ubuntu 22.04 is LTS (long-term support release) more and more developers and sysadmins use it for hosting NodeJS applications. In this article we will show the steps to install any version of NodeJS on Ubuntu 22.04 server.
NodeJS Release Versions
Node.js versions enter Current release status for six months, which gives library authors time to add support for them. Here is the release schedule as per Nodejs official website.
In the following table you can check the latest release of each version branch. This is useful in cases you wish to use a stable yet not latest release version of NodeJS on your server.
Steps to Install specific NodeJS version on Ubuntu 22.04 Server
The following steps are provided for installing NodeJS v18. You can use the same steps to install any other version, just by adjusting Step 3.
All commands below assume you are logged in to the server with root account. If you are using any other sudo privileged account, then prepend ‘sudo’ in all commands.
Step 1: Update & Upgrade System
Update your Ubuntu 22.04 system by running the following command:
root@netshopisp-nodejs:~$ apt update -y && apt upgrade -y
During the upgrade execution, you will be prompted with a window informing you about the kernel upgrade as shown below. Press “OK” to continue.
Then, you will be prompted to choose the daemon services to be restarted. You can stick to the default selected ones and press “OK” to continue.
Step 2: Reboot System
As the system’s kernel got updated, a reboot is necessary. Execute the following command to restart your server.
root@netshopisp-nodejs:~$ reboot
Step 3: Install specific NodeJS version from NodeSource
The NodeSource repository provides up-to-date releases of Node.js to ensure easy access to the latest features, bug fixes, and security updates related to Node.js.
The following command will pull the NodeSource repository for NodeJS v18 and NPM v10:
root@netshopisp-nodejs:~$ curl -fsSL https://deb.nodesource.com/setup_18.x | -E bash -
Sample Output:
Step 4: Install NodeJS v18
Now you are ready run the following command to install NodeJS v18 on the server:
root@netshopisp-nodejs:~$ apt-get install nodejs -y
Sample Output:
You have successfully installed NodeJS v18 on Ubuntu 22.04 Server. You can verify the nodejs and npm versions using the following commands:
root@netshopisp-nodejs:~$ node -v && npm -v
You can now proceed with configuring your NodeJS application on the server!