How to Install node.js on Debian: 3 Simple Methods

Try this guide with our instant dedicated server for as low as 40 Euros

install node.js on debian

node.js is a powerful JavaScript runtime built on Chrome’s V8 engine. It is a popular choice for building scalable and efficient web applications.

In almost all cases, the performance of a node.js-powered stack depends upon how you set it up. That’s why installing it the right way is a critical step in extracting the desired performance from the hosted applications.

If you’re using a Debian-based system and looking to get started with node.js, this installation tutorial will guide you through the various methods to install Node.js on your Debian machine.

Table Of Contents

  1. Install node.js on Debian
    1. Method #1: Install node.js via apt
    2. Method #2: Install node.js via NodeSource PPA
    3. Method #3: Install node.js via NVM
  2. Conclusion
  3. FAQs

Install node.js on Debian

Let’s start with installing node.js on Debian. We will discuss three methods that cover various sources, including the official Debian repository, the Node.js developer source, and NVM.

Method #1: Install node.js via apt

This method involves the official Debian repository. Note that this repository doesn’t always contain the latest node.js version. However, you will get a stable version on your machine.

Step #1: Update the System Index Repository

Before you start the installation process, you should make sure you start with an updated system’s package repository. This preparatory step ensures you have the latest and most stable package versions on your system. 

Launch the terminal and run the following command:

# sudo apt update

sudo apt update

Next, run the following command to upgrade the packages to the latest versions.

# sudo apt upgrade

Step #2: Install node.js

With your system repository index updated, you can now install node.js. 

Run the following command to get the latest version of the package from the Debian repository. 

# sudo apt install nodejs

sudo apt install nodejs

 Step #3: Verify the Installation

After the installation is complete, verify it by checking the version information by running one of the following commands:

# node --version

Or

# node -v

node --version v12 22 12

 

Method #2: Install node.js via NodeSource PPA

If you want more control over the version of Node.js you want to install, consider using a Personal Package Archive (PPA) provided by NodeSource, a respected brand in the node.js space. NodeSource manages its own APT repository that contains a variety of Node.js versions and related tools.

We recommend this method if you plan to set up multiple node.js versions on your Debian system and get the benefit of the latest features and updates.

Important: When you use the PPA for installation, node.js and NPM (the default package manager for Node.js) are included in the package.

Step #1: Make Sure You Have curl on the System

Ensure you have curl installed on your Debian system because we will use it to download the NodeSource installation script. 

So, if curl is not already installed, install it by running the following command:

# sudo apt install curl

sudo apt install curl

The message indicates that we already have the latest curl version on our test system. If it weren’t, the system would update it automatically. 

We recommend running the following command to check if the installation was successful:

# curl —-version

curl —-version

Step #2: Add PPA to the System

With curl installed, let’s use it to add the NodeSource PPA to your system. 

Remember, NodeSource provides various versions of Node. In our example, we used version 18.x. If you need a different version, simply swap setup_18.x with the specific version (for instance, 14.x or 16.x) you’re looking for.

We will run the following command to get the relevant PPA using the curl command:

# curl -sL https://deb.nodesource.com/setup_18.x  | sudo bash -

sudo bash

Step #3: Update the System Repository

After adding the PPA, update the system package repository and upgrade packages to include the newly added NodeSource packages:

# sudo apt update

# sudo apt upgrade

sudo apt upgrade

Step #4: Install node.js

Now, we are ready to install node.js. For this, run the following command:

# sudo apt install nodejs

sudo apt install nodejs 2

Step #5: Verify the Installation

Confirm the installation by printing out the version information with one of the following commands:

# node --version

OR

# node -v

node --version v18 19 1

Next, check the version of the npm package with the following command:

# npm -v

npm -v 10 2 4

Method #3: Install node.js via NVM

Node Version Manager (NVM) is a tool that allows you to manage multiple node.js versions on a system. This results in greater flexibility by leveraging the capabilities and features of specific node.js versions.

Step #1: Get the Installer Script

Start by downloading and running the NVM installation script from the project’s GitHub repository:

# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

curl -o

Step #2: Reload the Bash Profile

To start using NVM, you’ll need to reload the bash profile. 

You can do this by either closing and reopening your terminal or running the following command to reload without restarting the terminal:

# source ~/.bashrc

bashrc

Step #3: List the node.js Versions

Check the available node.js versions you can install with one of these commands:

# nvm list-remote

Or

# nvm ls-remote

nvm list-remote

As you can see, the command lists all available versions, giving users the option to select and install more than one version.

Step #4: Install node.js

Install your desired version of Node.js by specifying the version number. For example, to install node.js stable version 16.13.0, run:

# nvm install 16.13.0

nvm install 16.13.0

After node.js is installed on your system, it starts using the installed version by default. You can check which version is currently active by running:

# node -v

Step #5: Switch Versions

Since NVM enables users to download and install various versions of node.js, chances are that you have more than one version on your Debian system. To see a list of all the node.js versions you’ve installed, use the nvm ls command like this

# nvm ls

nvm ls

Now that you have verified that you have multiple versions of node.js installed, you can switch between them using:

# nvm use <version>

For instance, run the following command to use version 15.0.1:

# nvm use 15.0.1

nvm use 15.0.1

Let’s go back to the output of the nvm ls command that indicated that the current default node.js version is 16.13.0. If you want to set a different version, such as 15.0.1, as the default version, run the following command:

# nvm alias default 15.0.1

nvm alias default 15.0.1

Also Read: How to Install node.js and NPM On macOS: 3 Simple Methods

Also Read: Install Go in Debian in 4 Easy Steps

Conclusion

Installing node.js on Debian is straightforward, with multiple methods to choose from based on your specific needs. 

Whether you prefer the simplicity of the apt package manager, the control provided by NodeSource’s PPA, or the flexibility of NVM, each method has its advantages. Remember to consider RedSwitches’ bare metal hosting provider for high-performance hosting solutions to further enhance your Node.js applications.

Experience hosting perfection with RedSwitches. We offer unparalleled dedicated hosting solutions for seamless performance and global reach. Our product lineup has the best dedicated server pricing for instant dedicated servers. These servers are usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q. How do I uninstall Node.js?
To uninstall Node.js, use the apt remove command if installed via apt or nvm uninstall <version> for versions installed via NVM.

Q. Can I install multiple versions of Node.js on the same system?

 Yes, using NVM allows you to install and manage multiple Node.js versions on the same machine.

Q. How do I update Node.js to a newer version?
If you used apt, simply run sudo apt update && sudo apt upgrade. For NVM, install the new version with `nvm install `

Q. What are Debian repositories?

Debian repositories are online servers that store and distribute Debian software packages. They include thousands of precompiled packages managed by the apt package management system, making software installation and maintenance on Debian systems straightforward and efficient.

Q. How do I update the package list on Debian?

To update the package list on Debian, you use the apt update command. This command refreshes your local package index with the latest information from the Debian repositories, ensuring you can install the most recent versions of the software.

Q. Why is Debian a good choice for a development environment?

Debian is favored for development environments due to its stability, comprehensive package repositories, and strong community support. It provides a solid foundation for developers to build, test, and deploy applications efficiently.

Q. Why should I use the official Node.js repository instead of the Debian repository for installation?

The official Node.js repository often contains more up-to-date versions of Node.js compared to the Debian repositories. Using the official repository ensures you have access to the latest features, security patches, and improvements, which is crucial for developing modern web applications.

Try this guide with our instant dedicated server for as low as 40 Euros