Linux MintUbuntu Based

How To Install Node.Js on Linux Mint 22

Install Node.js on Linux Mint 22

In this tutorial, we will show you how to install Node.js on Linux Mint 22. Node.js is a powerful JavaScript runtime environment that has revolutionized the way developers build web applications. Its ability to handle asynchronous operations and its extensive ecosystem of packages make it a favorite among developers. Linux Mint 22, with its user-friendly interface and robust performance, is an excellent platform for developers to set up their development environment.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Node.js on Linux Mint 22.

Prerequisites

  • A server running one of the following operating systems: Linux Mint 22.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
  • An active internet connection.
  • Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.

Install Node.js on Linux Mint 22

Step 1. Update Your Linux Mint System.

Before installing any new software, it’s good practice to update your system’s package index. Open a terminal and run the following command:

sudo apt update
sudo apt upgrade

This command refreshes the list of available packages and their versions, ensuring you have the most up-to-date information.

Step 2. Installing Node.js.

  • Method 1: Installing Node.js Using the Default Package Manager

The simplest way to install Node.js on Linux Mint 22 is through the default package manager, APT (Advanced Package Tool). This method is straightforward but may not always provide the latest version of Node.js.

Now install Node.js using the default package manager:

sudo apt install nodejs

After installation, verify that Node.js and npm (Node Package Manager) are correctly installed by checking their versions:

node -v
npm -v
  • Method 2: Installing Node.js Using NodeSource Repository

For those who need a more recent version of Node.js, installing via the NodeSource repository is an excellent option. This method allows you to install the latest LTS (Long Term Support) version of Node.js.

If you have previously installed Node.js, remove it to avoid conflicts:

sudo apt purge nodejs
sudo rm -r /etc/apt/sources.list.d/nodesource.list
sudo rm -r /etc/apt/keyrings/nodesource.gpg

Add the NodeSource repository to your system. This will ensure you get the latest version of Node.js:

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -

Now, install Node.js from the added repository:

sudo apt install nodejs

Verify the installation by checking the versions of Node.js and npm:

node -v
npm -v
  • Method 3: Installing Node.js Using Node Version Manager (NVM)

Node Version Manager (NVM) is a powerful tool that allows you to install and manage multiple versions of Node.js on your system. This method is particularly useful for developers who work on projects requiring different Node.js versions.

Install NVM using the following command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

After installation, reload your shell configuration to apply the changes:

source ~/.bashrc

Now install the latest version of Node.js using NVM:

nvm install node

Verify that Node.js and npm are correctly installed:

node -v
npm -v

One of the significant advantages of using NVM is the ability to manage multiple versions of Node.js easily. Here are some useful commands:

List Installed Versions:

nvm list

Switch to a Specific Version:

nvm use <version>

Uninstall a Specific Version:

nvm uninstall <version>

Step 3. Setting Up a Development Environment.

After installing Node.js, you can set up your development environment by installing popular packages globally. For example, you can install Express.js and Create React App:

npm install -g express
npm install -g create-react-app

Step 4. Creating a Simple Node.js Application.

Create a simple Node.js server to test your installation. Create a file named app.js and add the following code:

const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
});

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

Run the application using the following command:

node app.js

Open your web browser and navigate to http://localhost:3000/ to see the “Hello World” message.

Congratulations! You have successfully installed Node.js. Thanks for using this tutorial to install the latest version of the Node.js on the Linux Mint system. For additional help or useful information, we recommend you check the official Node.js website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button