Skip to main content

Specific NodeJs version install with NVM


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.

Comments

Popular posts from this blog

Setup a Multi-Protocol VPN Server Using SoftEther on Centos7

  Introduction This article explains how to install and configure a multi-protocol VPN server using the SoftEther package. We enable and configure OpenVPN and L2TP over IPSec and SSTP VPN Servers on Linux. What is SoftEther SoftEther VPN is one of the world’s most powerful and easy-to-use multi-protocol VPN software, made by the good folks at the University of Tsukuba, Japan. It runs on Windows, Linux, Mac, FreeBSD and Solaris and is freeware and open-source. You can use SoftEther for any personal or commercial use free of charge. Step 1: Create a Virtual Server First, you need to create a DigitalOcean Droplet. As mentioned in SoftEther’s website, SoftEther will work on almost every Linux distro with kernel v2.4 or above,; however it’s recommended to choose one of these distributions: CentOS, Fedora, or Red Hat Enterprise Linux. Personally I have tried it on Ubuntu, CentOS and Fedora, both 32 and 64 bit editions, and it has worked perfectly. Step 2: Update your Server Software Usin...

Setting Up MariaDB MaxScale Binlog Proxy for backup/failover

  Setting Up MariaDB MaxScale Binlog Proxy MariaDB MaxScale Binlog Server acts as an intermediate master replication proxy. By storing binary logs and serving them to replicas, it enables scalable replication architectures, reduces primary database load, and accelerates disaster recovery. Step 1: Install MariaDB MaxScale Install MaxScale using the package manager appropriate for your Linux distribution, then verify the installation. On Ubuntu/Debian: sudo apt-get update sudo apt-get install maxscale On RHEL/CentOS: sudo yum install maxscale Verify the installation: maxscale --version Step 2: Configure MaxScale as a Binlog Proxy Open MaxScale's core configuration file to establish the routing properties and specify your database backend configuration. sudo nano /etc/maxscale.cnf Add the following configurations for the moni...

Deploying a laravel app using nginx alias

  server { listen 80; server_name subdomian.example.com; root /var/www/mainapp/; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; error_log /var/log/nginx/error.log warn; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location /laravelapp { alias /var/www/mainapp/laravelapp/public; index index.php index.html in...