How To Install Node.js on Linux Mint 20/19/18

Channel: Linux
Abstract: NVM is successfully installed on your system. Now you can install any node.js version with the help of NVM. nvm install 16.14you need to node.js PPA i

Node.js is a platform built on Chrome’s V8 JavaScript engine. Nodejs can used for easily building fast, scalable network applications. Latest version node.js ppa is maintaining by its official website. Also the NVM (Node Version Manager) provides you an option to install specific version or any number of Node.js versions for the logged in user.

How to Install Node.js on Linux Mint

This quick how-to guide provides you two methods to install Node.js & NPM on Linux Mint 20, 19 and 18 Linux systems.

Method 1 – Installing Node.js with Official PPA

First of all, you need to node.js PPA in our system provides by Nodejs official website. We also need to install the python-software-properties package if not installed already. You can choose either to install the latest Node.js version or the LTS version.

For Latest Release

sudo apt-get install curl python-software-properties software-properties-common 
curl -sL https://deb.nodesource.com/setup_17.x | sudo bash - 

For LTS Release

sudo apt-get install curl python-software-properties software-properties-common 
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash - 

For this tutorial, I have added the latest release Apt repository on my Linux Mint system. NPM will also be installed with node.js. This command will also install many other dependent packages on your system.

sudo apt-get install nodejs 
Method 2 – Installing Node.js with NVM

NVM provides a shell script for the installation on the Linux system. So, execute the installer script with the below commands. This will install the nvm command on your system.

sudo apt install curl 
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

Now, load the nvm environment in the current shell with the below command.

source ~/.profile 

NVM is successfully installed on your system. Now you can install any node.js version with the help of NVM.

nvm install 16.14 

You can run the above command with different-2 versions to install any number of Node.js on your Linux Mint systems. For example you can use nvm install 17 or nvm install 12.18 etc.

The systems have multiple node.js versions installed, can use the below command to set any installed node.js version as an active version.

nvm use 16.14 

You can find the detailed instruction’s about the node.js installation in our previous tutorials. Find more details about Node.js installation via NVM.

How to Check Default Node.js Version

After completing the installation process of node.js, Let’s check and verify the installed version. You can find more details about current version on node.js official website.

node -v  

v16.14.0

Also, check the version of NPM.

npm -v  

7.4.0
  • Don’t Miss => Yarn Installation ( A Node Modules Manager)
Step 4 – Create A Demo Web Server (Optional)

This is an optional step. If you want to test your node.js install. Let’s create a web server with 「Hello World!」 text. Create a file http_server.js

sudo nano http_server.js 

and add the following content

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');

Now start the webserver using the command.

node http_server.js 

Server running at http://127.0.0.1:3000/

Web server has been started on port 3000. Now access http://127.0.0.1:3000/ url in browser.

Ref From: tecadmin

Related articles