If you’re a web developer working on the front-end or back-end, you’ll need: Node.js installed on your system.
But using the typical sudo apt install nodejs
Running the command may install a very old version of Node, which can be a hassle.
Therefore, you need to install a specific version that requires a different command. This installs the LTS (Long Term Support) version of Node. This is useful for developers as it has a long support period.
Today I’m going to show you how to install the latest LTS version of Node on the Ubuntu operating system.
This process works on all kinds of Debian-based Linux operating systems (Ubuntu, Mint, Zorin, Debian, Elementary OS, etc.). This applies to virtual machines (VMware Workstation, VirtualBox, etc.) whether you are using them as the main operating system, as a secondary operating system in a dual boot, or as a WSL on Windows. It works even if you are using
video tutorial
We’ve also created a complete video to walk you through the process step by step. You can watch it here:
As of this writing, the latest LTS version of Node is 18.18.2.
When you install Node by following the steps in this article, the latest LTS version of Nodejs is automatically installed. So just follow this article and the accompanying video and it will be hassle-free and safe.
Update your operating system
First, make sure all updates are installed beforehand. I mostly like working in the terminal, so I use it directly to install updates.
To update all related packages to the latest versions, use: sudo apt update
Inside the terminal. If you are asked for a password, please use it.
Use it now sudo apt upgrade -y
Upgrade all upgradable packages.
Install CURL
What we are using is Node Version Manager (NVM) Now install Node. Installing Node and npm using NVM has various benefits as it allows you to manage multiple versions of Node.js on your system together.
First you need to install curl
If it is not already installed on your system. You can install curl using the command below.
sudo apt install curl -y
How to install Node.js
To ensure that Node.js is successfully installed on your system, you need to follow these steps:
Install Node Version Manager (NVM)
Install Node Version Manager (NVM) using the following command:
curl -o- | bash
When you run this particular command, curl will download the NVM installation script from that particular URL. Then bash runs the same script to install her NVM.
Activate NVM
Activate NVM using the following command:
source ~/.bashrc
Install the latest LTS version of Node
Install the latest long-term support version of Node using the following command:
nvm install --lts
By default, the latest version of the LTS release of Node is installed.
Create the default LTS version as NVM
Although you have installed the latest LTS version of Node, you also need to set the default version of NVM so that it is used by default whenever you need it. You can do this using the command below. Change the version to the exact LTS version you just installed on your system.
nvm alias default 18.18.2
If your LTS version is: 24.1.2
In that case, the command would look like this:
nvm alias default 24.1.2
Verify that node is installed
Check if the default version is the exact version you just installed using the command below.
node -v npm -v
How to set up a Node.js environment
After installing Node and NPM, you need to set up your Node environment by creating a new Node project.
Create a new directory/folder to test a simple “Hello World” type node project using the command below.
mkdir my-node-project
Go to. my-node-project
Create a directory using the command below.
cd my-node-project
Initialize a new Node project as follows:
npm init -y
This command creates a “package.json” file containing your project’s metadata and dependencies. The JSON output is as follows:
The JSON output is below.
"name": "my-node-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts":
"test": "echo "Error: no test specified" && exit 1"
,
"keywords": [],
"author": "",
"license": "ISC"
Then run the setup using simple commands. For this, create a new file with the following name: app.js
using Nano A text editor in the terminal.
sudo nano app.js
When the text editor opens, enter the following code.
console.log("Hello, Node.js from Ubuntu!");
use Ctrl
+ O
Save the file.use Enter
To save the file as app.js
:
use Ctrl
+ X
Return to the bash terminal again.
Then check the output to see if it’s working.
Use the command below.
node app.js
It’s working!
You have successfully installed the latest LTS release of Node on your Ubuntu/Debian-based Linux operating system.
cheers! 🥂
conclusion
Thank you for reading this article all the way to the end.
If you like our step-by-step instructions, please let us know. Twitter/X Or LinkedIn.
If you’re interested in open source, follow me on GitHub. Be sure to check out my website too (that too!
If you want to watch programming and technology related videos, check out my YouTube channel as well.
Good luck in your programming and development journey. 😊
I can do it! Never give up! ❤️