Linux Mint

How to Install Node.js on Linux Mint 21

Node.js is an open-source, asynchronous backend JavaScript runtime platform. It’s a powerful cross-platform runtime to build server-side projects in JavaScript language. Its non-blocking, I/O model feature makes it a more efficient, powerful, and fast environment.

Node.js has unlimited features but some of the most nominated that make it a JS developer’s choice are mentioned here. It comes with the MIT license having a single threaded model. It is asynchronous which means it never waits for the previous API’s response and outputs the data in chunks (no buffering).

Install Node.js on Linux Mint 21

To install Nodejs on Linux Mint 21 system, follow the steps mentioned below:

Step 1: Update the system’s repository with the help of the given command to upgrade all packages up-to-date:

$ sudo apt update

Step 2: In this step, you are required to install all the dependencies as they are prerequisite of it; so, execute the command given below:

$ sudo apt install software-properties-common apt-transport-https ca-certificates gnupg2 curl build-essential

Step 3: Once you installed all the required dependencies, run the mentioned command to get Node-source repository in your system:

$ curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

Step 4: Now you can install the Node.js application on Linux Mint 21 system after successfully set node source repository:

$ sudo apt install nodejs

Step 5: Execute the following command to verify installed of Node.js version on system:

$ node --version

Test Node.js on Linux Mint 21

Create a simple JavaScript file using nano editor and type a simple program in it:

$ nano test_file.js

const http = require('http');
const port = 3000;
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(‘Hello This is LinuxHint! and I am Sam\n’);
});
server.listen(port, () => {
console.log(`Listening Port ${port}`);
});

Save this program on the editor and open any browser to see the output. For this run the command given below in the terminal. This would start running a web server on local port 3000:

$ node test_file.js

To verify successful installation of Nodejs, type in browser:

localhost:3000

How to Remove Node.js from Linux Mint 21

To uninstall Node.js from the Linux Mint 21 system, the mentioned command would be executed in terminal:

$ sudo apt remove nodejs

Conclusion

Node.js is an open-source JavaScript runtime used to create JavaScript based projects. It is popular among developers who wish to build applications in a non-blocking environment.

In this article, we have mentioned in-depth details about the installation process of Node.js on the Linux Mint 21 system. We have also run a test file to show its web server working. Moreover, we have also mentioned the command to uninstall it.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.