• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Node.js and npm on Debian 9

Written by Admin, Updated On July 18, 2019
debian, nodejs, npm, nvm
How to Install Node Js on Debian 9

Node.js is an opensource 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. In this tutorial, we will learn how to install Node.js and npm on Debian 9.

Install Node.js and npm on Debian#

There are multiple ways to install Node.js and npm on your Debian 9 systems. You can follow any of following to install:

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.

At first, you need to add NodeSource repository on your system using following curl command:

curl -sL https://deb.nodesource.com/setup_10.x | 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
Output
v9.10.1
npm --version
Output
5.6.0

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.

At first, we need to download nvm install script on your system using below command:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | 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.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion

As you can see in output, 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
Output
0.33.11

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…
Downloading https://nodejs.org/dist/v12.0.0/node-v12.0.0-linux-x64.tar.xz…
################################################################## 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
Output
v12.0.0

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
v10.15.3
v12.0.0
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
Output
v10.15.3

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

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

Conclusion#

Finally, you have learned how to install nodejs and npm on your Debian system with different methods. At the end of tutorial you also learned how to uninstall it.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Check Debian Version with Different Methods
Next Article   How to Change Hostname on Ubuntu 18.04

Related Posts

  • How to Install WordPress with Nginx on Debian 11

    How to Install WordPress with Nginx on Debian 11

    March 22, 2023
  • How to Install and Use Docker on Debian 11

    How to Install and Use Docker on Debian 11

    March 10, 2023
  • How to Install MariaDB on Debian 11 Bullseye

    How to Install MariaDB on Debian 11 Bullseye

    March 8, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook