
Node.js is an opensource cross-platform JavaScript run-time environment built on Chrome’s JavaScript for server-side execution. npm is the very popular and default package manager for Node.js with large number of packages. This tutorial explains how to install Node.js and npm on Debian 10.
Install Node.js and npm from the Debian repositories
You can install Node.js and npm from the standard Debian repositories. The version in the repositories is v10.x which is the latest LTS version. To install Node.js and npm from standard Debian repositories is the easiest way.
Run the following command to install Node.js and npm on your Debian system:
sudo apt update
sudo apt install nodejs npm
After that, verify the installation by typing:
nodejs --version
It will should output as following:
v10.15.2
Install Node.js and npm from the 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:
To install Latest Version
curl -sL https://deb.nodesource.com/setup_13.x | sudo bash -
For latest LTS Version
curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -
Here, we are installing latest version v.13.x.
After adding repository run the below command to install Node.js and npm:
sudo apt install nodejs
Check Node.js installation by typing:
node --version
v13.3.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:
Do not use sudo as it will enable the script for the root user.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.0/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 the nvm installation by typing:
nvm --version
0.35.0
Now you have nvm installed on your CentOS 8 system. You can install the latest available stable version of Node.js using below command:
nvm install node
It will show output as below:
... Computing checksum with sha256sum Checksums matched! Now using node v13.3.0 (npm v6.13.1) Creating default alias: default -> node (-> v13.3.0)
Once the installation is finishe you can check the version of Node.js by typing :
node --version
v13.3.0
Next, We will install two more versions of Node.js. To do so type following:
nvm install --lts
nvm install 10.17.0
Once the both of above versions are installed we can view list using below command:
nvm ls
-> v10.17.0 v12.13.1 v13.3.0 default -> node (-> v13.3.0) node -> stable (-> v13.3.0) (default) stable -> 13.0 (-> v13.3.0) (default) iojs -> N/A (default) lts/* -> lts/dubnium (-> v12.13.1) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.16.2 (-> N/A) lts/dubnium -> v10.17.0 lts/dubnium -> v12.13.1
In output version with arrow is represent current shell session. Default version is set to v10.17.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 12.13.1
Now verify it by typing:
nvm current
v12.13.1
You also can set set version 12.13.1 as the default Node.js version using below command:
nvm alias default 12.13.1
You can uninstall a Node.js version type following command:
nvm uninstall 10.17.1
Install development tools
To be able to build native modules from npm we will need to install the development tools and libraries:
sudo apt install build-essential
Uninstalling Node.js
If you want to uninstall Node.js and npm packages, use the following command:
sudo apt remove nodejs npm
Conclusion
In this guide you learned different ways to install Node.js and npm on your Debian 10 system. If you have any qery or feedback, feel free to comment below.
Leave a Reply