A Comprehensive Guide to Installing Node.js on Linux

August 22, 2023 Community, Developers, Linux, Node.js
Avatar photo

Russell Bates

Node.js has gained immense popularity among developers for building fast and scalable server-side applications. If you’re a Linux user, you’re in luck! Installing Node.js on Linux is a straightforward process that allows you to leverage the power of this runtime environment for your projects. In this article, we’ll walk you through the step-by-step process of installing Node.js on various Linux distributions.

Why Node.js?

Node.js is a runtime environment built on Chrome’s V8 JavaScript engine. It allows developers to execute JavaScript code outside of a web browser, making it ideal for creating server-side applications. Node.js’s event-driven, non-blocking architecture enables building real-time applications that can handle a large number of concurrent connections efficiently. It has a rich package ecosystem, with npm (Node Package Manager) being one of the largest package registries globally.

Prerequisites

Before you begin the installation process, ensure you have the following prerequisites:

  1. Linux Distribution: This guide covers installation on Ubuntu, Debian, CentOS, and Fedora. Choose the distribution that suits your needs.
  2. Terminal Access: You’ll need a terminal to execute commands.

Installing Node.js

1. Ubuntu/Debian

For Ubuntu and Debian-based systems, you can use the package manager to install Node.js. Open your terminal and follow these steps:

  1. Update the package list:sql
sudo apt update

Install Node.js and npm:

sudo apt install nodejs npm

Verify the installation:

  1. node -v npm -v

2. CentOS

On CentOS, you can use the Node.js version from the EPEL (Extra Packages for Enterprise Linux) repository. Follow these steps:

  1. Install the EPEL repository:arduino
sudo yum install epel-release

Install Node.js and npm:

sudo yum install nodejs npm

Verify the installation:

  1. node -v npm -v

3. Fedora

For Fedora, you can install Node.js from the official Fedora repositories:

  1. Update the package list:sql
sudo dnf update

Install Node.js and npm:

sudo dnf install nodejs npm

Verify the installation:

  1. node -v npm -v

Managing Node.js Versions with NVM (Node Version Manager)

While package managers are great for installing Node.js, you might need to work with different versions for different projects. This is where NVM comes in handy. NVM allows you to manage multiple Node.js versions on a single system. Here’s how to set it up:

  1. Installing NVM
  2. Run the following commands in your terminal:bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

Close and reopen your terminal or run:

source ~/.bashrc

Now you can install different Node.js versions.

Installing Node.js using NVM

Install the latest LTS (Long Term Support) version of Node.js:

nvm install --lts

Install a specific version:

nvm install 14.17.5

Switching Node.js Versions

To use a specific version, run:

nvm use 14.17.5

Setting Default Node.js Version

If you want a specific version to be the default, run:

  1. nvm alias default 14.17.5

Conclusion

Installing Node.js on Linux is a crucial step to kickstart your server-side development journey. With its powerful capabilities and expansive package ecosystem, Node.js provides a robust platform for building modern applications. Whether you’re a beginner or an experienced developer, the installation process outlined in this guide should help you get started smoothly. Remember that while package managers simplify the process, tools like NVM enable you to manage different Node.js versions effectively. Now that you have Node.js up and running, you’re ready to dive into the exciting world of server-side programming. Happy coding!