Rishu
Back to Blog

How to Install Node.js on Linux: A Comprehensive Guide

LinuxNode.jsTutorialWeb Development
Advertisement Space

Introduction

Node.js is a powerful JavaScript runtime built on Chrome's V8 JavaScript engine. It's an essential tool for modern web development, allowing you to run JavaScript on the server side. Installing Node.js on Linux is straightforward, but there are a few methods to choose from depending on your needs.

Method 1: Using Node Version Manager (NVM) - Recommended

Using NVM is highly recommended because it allows you to install and switch between multiple versions of Node.js with ease. This is especially useful if you are working on different projects that require different Node.js versions.

Step 1: Install NVM

First, you need to download and install the NVM script. Open your terminal and run:

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

Step 2: Reload your terminal

Close and reopen your terminal, or source your profile to apply the changes:

source ~/.bashrc

Step 3: Install Node.js

Now you can install the latest Long Term Support (LTS) release of Node.js:

nvm install --lts

Method 2: Using NodeSource PPA (Ubuntu/Debian)

If you prefer using the built-in package manager (APT) and want a specific, up-to-date version of Node.js, the NodeSource repository is the way to go.

Step 1: Add the NodeSource repository

For Node.js 20.x, run the following command:

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

Step 2: Install Node.js

After the setup script finishes, install Node.js using APT:

sudo apt-get install -y nodejs

Verifying the Installation

Whichever method you chose, you can verify your installation by checking the Node.js and npm (Node Package Manager) versions:

node -v
npm -v

Conclusion

You have successfully installed Node.js on your Linux machine! You are now ready to start building incredible full-stack web applications. NVM provides the most flexibility, but NodeSource is great for straightforward server deployments.

Advertisement Space