Install Node.js and npm on Debian 9 - Step by Step Process ?

Node.js is an Open source cross-platform JavaScript run-time environment for server-side execution of JavaScript code. It's built on Chrome's JavaScript engine so it can be used to build different types of server-side application. npm is the very popular and default package manager for Node.js with large number of packages.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Node js queries.

In this context, we shall look into how to install Node.js and npm on Debian 9.

How to Install Node.js and npm on Debian / Ubuntu ?

There are different methods to install Node.js and npm on your Debian systems. You can follow any of following to install.

1. Install Node.js from NodeSource Repository

NodeSource provides a repository containing latest version of Node.js and npm. It's very simple to install Node.js and npm from NodeSource.

To begin, you need to add NodeSource repository on your system using following curl command:

$ curl -sL | sudo bash -

NOTE : The latest LTS version of Node.js is 10.x if you want to install 8.x version then just replace setup_10.x with setup_8.x

After that, install Node.js and npm with the following command:

$ sudo apt install nodejs

Verify installation of Node.js and npm running below command:

$ node --version
$ npm --version

2. Install Node.js and npm using nvm

NVM (Node Version Manager) script is used to manage multiple Node.js versions. You can install or uninstall specific Node.js versions using NVM.

To begin, we need to download nvm install script on your system using below command:

$ curl -o- | bash

It will copy the nvm repository from Github to the ~/.nvm directory and add the nvm path to your Bash profile:

=> Close and reopen your terminal to start using nvm or run the following to use it now:
 export NVM_DIR="$HOME/.nvm"
 [ -s "$NVM_DIR/" ] && . "$NVM_DIR/"  # This loads nvm
 [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

Here, it is suggesting to either open new shell session or run the commands to add the path to the nvm script to your current session.

You can verify that nvm is installed properly by typing:

$ nvm --version

Now you have nvm installed on your Debian system. You can install the latest available version of Node.js using below command:

$ nvm install node

It will show output as below:

Downloading and installing node v12.0.0…
################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.0.0 (npm v6.9.0)
Creating default alias: default -> node (-> v12.0.0)

Once the installation is finished you can check the version of Node.js by typing :

$ node --version

Next, We will install two more versions of Node.js. To do so type following:

$ nvm install --lts
$ nvm install 9.10.1

Once the both of above versions are installed we can view list using below command:

$ nvm ls
->      v9.10.1
 default -> node (-> v12.0.0)
 node -> stable (-> v12.0.0) (default)
 stable -> 12.0 (-> v12.0.0) (default)
 iojs -> N/A (default)
 lts/* -> lts/dubnium (-> v10.15.3)
 lts/argon -> v4.9.1 (-> N/A)
 lts/boron -> v6.17.1 (-> N/A)
 lts/carbon -> v8.16.0 (-> N/A)
 lts/dubnium -> v10.15.3

In output version with arrow is used for the current shell session. Default version is set to v12.0.0 and it will be used when you open new shell sessions.

You can change the current default version of Node.js by using the following command:

$ nvm use 10.15.3

Now verify it by typing:

$ nvm current

You also can set set version 10.15.3 as the default Node.js version using below command:

$ nvm alias default 10.15.3

You can uninstall a Node.js version type following command:

$ nvm uninstall 9.10.1

How to Uninstall Node.js and npm ?

To uninstall Node.js use following command:

$ sudo apt remove nodejs npm
$ sudo apt autoremove

To uninstall node.js version using nvm type following command:

$ nvm uninstall 10.15.3

[Need help in fixing Debian system errors? We can help you. ]

This article covers how to install nodejs and npm on your Debian system with different methods. Also, you will learn how to uninstall npm from your Debian system. Node.js is a JavaScript platform for general-purpose programming that allows users to build asynchronous network applications quickly. By leveraging JavaScript on both the front and backend, Node.js can make web application development more consistent and integrated.

To Install the Official Debian Node.js Package:

1. To get Node.js from the default Debian software repository, you can use the apt package manager. First, refresh your local package index:

$ sudo apt update

2. Then install the Node.js package, and npm the Node Package Manager:

$ sudo apt install nodejs npm

3. To verify that the install was successful, run the node command with the -v flag to get the version:

$ node -v

To Remove Node.js:

1. To remove either of these versions, type the following:

$ sudo apt remove nodejs

2. To uninstall a version of Node.js that you have enabled using nvm, first determine whether or not the version you would like to remove is the current active version:

$ nvm current

3. If the version you are targeting is not the current active version, you can run:

$ nvm uninstall node_version

This command will uninstall the selected version of Node.js.

4. If the version you would like to remove is the current active version, you must first deactivate nvm to enable your changes:

$ nvm deactivate

Related Posts