How to Install Node.js on Debian

Introduction

Node.js is a popular open-source JavaScript runtime environment that allows developers to create server-side applications. It is a great platform for building web applications and services. In this tutorial, we will show you how to install Node.js on Debian. We will cover the installation of both the Node.js package from the official Debian repositories as well as the NodeSource package. We will also show you how to configure the Node.js environment and how to verify the installation. So let’s get started!

How to Install Node.js on Debian

1. Update the apt package index:

sudo apt update

2. Install the NodeSource Node.js 12.x repo:

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash –

3. Install Node.js and npm:

sudo apt install nodejs

4. Check the version of Node.js and npm:

node -v
npm -v
[ad_1]

Introduction

Node.js is an open-source JavaScript (JS) runtime environment mostly used for the development of online apps. This cross-platform environment is lightweight and efficient due to its event-driven, non-blocking I/O model.

This guide will teach you how to install Node.js on Debian using three different methods.

How to Install Node.js on Debian

Prerequisites

Method 1: Install Node.js via apt

The simplest method for installing Node.js on Debian is from the official repository.

Note: The Node.js version included in the Debian repository could be outdated. Older Node.js versions are suitable for experimentation but should not be used in production environments.

To install Node.js from Debian’s repository, follow the steps below.

Step 1: Update the Repository

Before installing Node.js, ensure the repository pulls the latest version of the package containing Node.js. To do that, update system repositories with:

sudo apt update
sudo apt update terminal output

Next, upgrade packages to the latest version with:

sudo apt upgrade
sudo apt upgrade terminal output

Step 2: Install Node.js

Once the repository has been updated, proceed with the installation. Use apt install to install Node.js and NPM, the default package manager for Node.js.

Execute the following command:

sudo apt install nodejs npm -y
sudo apt install Node.js NPM -y terminal output

Step 3: Verify the Installation

Run -v to check the version of Node.js and NPM, verifying that packages have been installed:

<code>node -v
node -v terminal output

Verify the NPM installation with:

npm -v
npm -v terminal output

Method 2: Install Node.js via NodeSource PPA

The latest version of Node.js might not be available in Debian’s repository. If that’s the case, to get the latest version of Node.js use the PPA repository by NodeSource. PPA is an alternative repository, providing software not available in the official Debian repositories.

Step 1: Install the curl Command

Installing Node.js from PPA requires the use of curl. To install the latest version of curl, run:

sudo apt install curl
sudo apt install curl terminal output

The output shows that curl is up to date. In case it is not, the system updates the command. To verify the installation, run:

curl --version
curl --version terminal output

Step 2: Add PPA to the System

Add PPA to the system with:

<code>curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
add PPA with curl terminal output

Note: NodeSource offers different Node versions. The example uses 18.x. To download another version, replace setup_18.x with the version in question.

Step 3: Update Repository

Once the system adds the PPA, update the repository and upgrade packages:

<code>sudo apt update
sudo apt update PPA terminal output
sudo apt upgrade
sudo apt upgrade PPA terminal output

Step 4: Install Node.js

When installing from the PPA, Node.js and NPM come in the same package. Install both with:

<code>sudo apt install nodejs
sudi apt install Node.js terminal output

Step 5: Verify the Installation

To confirm Node.js and NPM are installed correctly, check their versions with -v:

node -v
node -v PPA installation terminal output
npm -v
NPM -v PPA installation terminal output

Method 3: Install Node.js via NVM

Another way to install Node.js is with the Node Version Manager (NVM).

NVM manages active Node.js versions. With NVM, users are able to download and switch between multiple Node.js versions using the terminal.

Step 1: Get the Installer Script

To install NVM, download the installer from GitHub first. Run the following command:

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Download NVM installer terminal output

Step 2: Reload the Bash Profile

Use one of two ways to add the path to the NVM script in the current shell session:

  1. Restart the terminal.
  2. Run the source ~/.profile command.
Reload the bash profile terminal output

Step 3: List Node.js Versions

Use the following command to list all available Node.js versions:

nvm ls-remote
nvm ls remote terminal output

The command prints all available versions, allowing users to choose and install more than one.

Step 4: Install Node.js

Use nvm install to download and install any specific version. For instance, to install version 12.1, run:

nvm install 12.1
nvm install 12.1 terminal output

Once the system installs Node.js, the installed version is the one used. Verify the version currently in use with:

node -v
node -v NVM installation terminal output

Step 5: Switch Versions

NVM allows users to download and install multiple versions. For instance, download and install versions 18.1 and 16.5 as well:

NVM install multiple versions terminal output

To list all installed versions, run nvm with ls command:

nvm ls
nvm ls terminal output

The command shows three versions, with the currently active one printed in green.

To switch to another version, use:

nvm use 18.1
nvm use terminal output

The ls output also shows that the default version is 12.1.

nvm ls default version terminal output

To change the default Node.js version, run:

nvm alias default 18.1
nvm alias default terminal output

Conclusion

After reading this tutorial, you know how to install Node.js and NVM on Debian. Next, learn how to update Node.js to the latest version.

[ad_2]

How to Install Node.js on Debian

Node.js is a popular JavaScript runtime environment that can be used to create web applications and other server-side applications. It is an open-source, cross-platform runtime environment for developing server-side and networking applications. In this tutorial, we will show you how to install Node.js on a Debian 10 system.

Prerequisites

  • A Debian 10 system
  • A user account with sudo privileges

Installing Node.js on Debian 10

Node.js is available in the default Debian 10 repositories. You can install it using the apt package manager.

First, update the apt package index:

sudo apt update

Once the package index is updated, install Node.js and npm with the following command:

sudo apt install nodejs npm

The apt package manager will install Node.js and npm in the default location. To verify the installation, check the version of Node.js and npm with the following command:

nodejs -v
npm -v

You should get the following output:

v10.19.0
6.14.4

You have successfully installed Node.js and npm on your Debian 10 system.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00