A runtime environment is used to run an application or execute certain tasks on a server or web browser. This acts as a small operating system for a program, as it contains all the necessary functionality to run. Usually, the run time environment is based on JavaScript language and Node.js is the JavaScript runtime environment. This allows the JavaScript code on servers but is different from the traditional JavaScript in the browsers.
Node.js enables the user to develop or create full-stack applications which include its back-end and front-end only in JavaScript. Since Node.js is open-source and supports cross-platform, it is compatible with the newly released Ubuntu 24.04, to install it on Ubuntu 24.04 there are multiple ways which will be discussed in this guide.
Outline:
- How to Install Node.js on Ubuntu 24.04
- Through Ubuntu Default Repository
- Through Node Version Manager
- Through Node Source
- Through Node Repository
- Through Tar file
- How to Remove Node.js from Ubuntu 24.04
- Conclusion
How to Install Node.js on Ubuntu 24.04
Node.js is an event-driven and non-blocking I/O model that allows its users to handle asynchronous tasks efficiently. Furthermore, it comes with a package manager, which simplifies managing the external libraries and modules. To install Node.js on Ubuntu 24.04 there are primarily five ways which are:
1: Through Ubuntu Default Repository
The default method to install any application on Ubuntu 24.04 is by using its default package installer but sometimes the apt package installer has an older version in its repository. The same is the case for Node.js:
Verify it by checking the version:
If you see in the screenshot for Node.js installation the compiler suggests installing the package manager as it will help in updating, installing, and sharing packages:
2: Through Node Version Manager
If you are looking forward to installing multiple versions of Node.js and npm then use the node version manager to install Node.js on Ubuntu 24.04. First, you need to install the node version manager using GitHub, to download nvm and run its script via bash shell execute:
Now execute the contents of the bash script file to apply the changes made by the node version manager:
Now you can verify the node version manager installation by looking for its version. Before installing Node.js via nvm, first, list all the available versions:
Here as you can see there is a huge list of versions available so for a demonstration I am going to install version 18 same as was installed in the previous method:
To install the desired version just use the below-given syntax:
Once the installation is complete now verify it by listing the node.js versions installed via nvm:
Here is the list you can see that each version has its name so instead of writing the version number you can install any node.js version by using its name:
Now in the image below the selected version that is currently active is 20 however the default version is still 18:
You can change the versions if there are any compatibility or any other similar issues, to change the current version execute:
Further, to change the default version of Node.js to the desired one execute:
3: Through Node Source
In the previous method, you can observe that the latest version available in the node version manager was 20 but currently, the latest version is 21. To install the latest version of node.js on Ubuntu 24.04 you can use its repository from GitHub. To download the node.js repository for the latest version and to execute it through bash shell execute:
Now update the packages list for the default package installer and then execute the below command to install Node.js:
After the installation, verify the version of node.js:
4: Through Node Repository
Installing an application through its source code or by manually configuring the repository is a slightly difficult process. However, using this method you can install any desired version as in this method a mirror link for the node.js will be added. First, there are some utilities that you need to install, but if they are already installed then skip it:
Next, if your keyring directory is missing then to create execute the below command, again this is an optional step:
Now set the version you want for node.js by making it an environmental variable, next get the GPG key for the node.js and then add the node source URL which as result will be added to the sources list. The command below sets up a new package repository for node.js from Node Source Repository and adds it to the system package source list:
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
Now update the packages list of apt and then install node.js by executing:
5: Through Tar File
The last method for installing Node.js on Ubuntu 24.04 is by downloading its compressed file from the download section of its official website. There are two ways to download it one is by downloading its directly from the website:
Or using the wget utility along with the download link:
Once the file is downloaded extract it:
Now before moving forward some dependencies might be needed to install Node.js successfully on Ubnutu which include:
- Zlib1g-dev: This package contains the header files and libraries necessary for developing software that use zlib.
- libncursesw5-dev: This package provides the necessary development files for ncurses library with wide character support.
- build-essential: This package installs some development tools including gcc compiler and make utility.
- libncurses5-dev: This package provides the necessary development files for ncurses library without wide character support
- libffi-dev: This package contains development files for libffi which provides a foreign function interface for calling functions written in other languages.
- libbz2-dev: This is a compression library used to compress and decompress files
- libsqlite3-dev: This package provides a development file for SQLite database engine.
- ibssl-dev: This package comes with the development files for the OpenSSL library.
Now navigate to the extracted file directory and execute the ./configure file to check for dependencies make file generation and configure compilation configuration:
./configure
Now compile the configuration files using the make command. Here the process takes a lot of time so I have added the instruction to run 4 parallel tasks as this would lessen the compilation time:
Now install Node.js by installing the make file created as a result of compilation:
After the installation reboot the system to apply the changes and then verify the installation by executing the version command:
How to Remove Node.js from Ubuntu 24.04
While removing an application from Ubuntu 24.04 or any other Linux distribution it is necessary to remove all the files and unnecessary dependencies. This is because they carry up some space and also might affect other installed applications. So to remove Node.js from Ubuntu 24.04 if installed though, node source, Ubuntu default package manager, and node repository then execute:
Next in the case of the node repository or node source delete the node source file in the sources list directory:
To uninstall Node.js if installed through node version manager then first look for the current node version:
Next, deactivate the current active node.js version:
Afterward, uninstall all the installed versions, to check the installed versions you can first list all the installed versions:
nvm uninstall v18.19.1
To remove node version manager from Ubuntu 24.04 first you need to deactivate it by unloading it:
Then remove the following lines of code from the bash shell configuration file:
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" #
To apply the changes reload the daemon service:
Similarly, if you have installed Node.js via its tar file or source code then in that case navigate to its extracted directory and uninstall the make file for Node.js:
After that remove the tar file and the extractor folder directory:
sudo rm node-v21.7.1.tar.gz
Note: Perform a system reboot once you have removed Node.js from Ubuntu 24.04 regardless of the method followed for installation or removal.
Conclusion
To install Node.js on Ubuntu 24.04 there are five different ways: Through Ubuntu Default Repository Node Version Manager, Node source repository, Node repository, and through tar file. Among these, the recommended way to install Node.js is by using the NVM. This is because one can install multiple versions of it which can be switched depending on the need.
I’m Aaliyan javaid, an electrical engineer and a passionate tech enthusiast. I have been working with embedded systems, programming, and Linux operating systems for over 2 years. I love to explore new technologies and share my knowledge and experience with others.