How to Install Node.js on Fedora 39/38/37 Linux

Node.js is a powerful, open-source, cross-platform JavaScript runtime environment that allows developers to build server-side applications using JavaScript. Initially released in 2009 by Ryan Dahl, Node.js has become an essential tool for developers across the globe, enabling them to create high-performance, scalable, and versatile applications.

Some of the key features and benefits of Node.js include:

  • Event-driven architecture: Node.js uses an event-driven, non-blocking I/O model, which makes it well-suited for scalable and real-time applications, as it efficiently handles multiple simultaneous connections.
  • JavaScript on the server-side: Node.js allows developers to use JavaScript on both the client and server-side, streamlining the development process and making it easier to maintain code.
  • Built-in package manager: Node.js comes with a built-in package manager called NPM (Node Package Manager), which provides access to thousands of reusable packages and modules to extend your application’s functionality.
  • Cross-platform compatibility: Node.js is compatible with major operating systems, including Windows, macOS, and Linux, allowing developers to create applications that run on various platforms.
  • Large community support: Node.js boasts a large and active community that continuously contributes to its development and improvement, ensuring that the platform remains up-to-date with the latest trends and technologies.
  • Wide adoption: Many prominent tech companies, such as Netflix, LinkedIn, and Walmart, have embraced Node.js for their applications, solidifying its reputation as a reliable and robust platform.

As a developer or system administrator, it’s crucial to understand the different methods of installing Node.js on your Fedora Linux system. The guide will demonstrate how to install Node.js on Fedora Linux using CLI commands and three different methods that have separate advantages depending on what you are looking for, which is installing directly from Fedora’s repository, installing the latest stable or latest LTS Node.js release from NodeSource RPM, or using NVM to install and manage Node.js.

Section 1: Install Node.js from Fedora Repository

This section will delve into installing Node.js directly from the Fedora repository. This method is simple and convenient, as it uses the default package manager of Fedora, DNF, to install Node.js. This ensures that the installed version of Node.js is compatible with your Fedora system and its dependencies.

Step 1: Update Your System

Before installing Node.js, it’s crucial to ensure your system is up-to-date. Keeping your system updated minimizes potential compatibility issues and ensures that you have access to the latest features and security patches. To update your Fedora system, open the terminal and run the following command:

sudo dnf upgrade --refresh

This command instructs DNF to update all installed packages on your system.

Step 2: Install Node.js from Fedora Repository

After updating your system, you can proceed with the installation of Node.js. Using the DNF package manager, you leverage Fedora’s official repository, ensuring the software is stable and secure. To install Node.js, execute the following command in your terminal:

sudo dnf install nodejs

Once the installation is complete, Node.js will be available on your Fedora system.

Section 2: Install Node.js using NodeSource RPM

This section will explore another method to install Node.js on Fedora: the NodeSource RPM. This approach offers several advantages, including the ability to install specific versions of Node.js that might not be available in the Fedora repository. NodeSource is a reliable source for the latest Long Term Support (LTS) and Current releases of Node.js, ensuring that you have access to the most recent features, performance improvements, and security updates.

Using NodeSource is highly recommended for developers who want to stay up-to-date with the latest LTS or Current releases, as the Fedora repository might not always provide the newest versions in a timely manner.

Step 1: Add NodeSource Repository

First, add the NodeSource repository to your Fedora system. This enables you to access and install Node.js directly from NodeSource. Run the following command to add the NodeSource repository for the LTS release:

curl -sL https://rpm.nodesource.com/setup_lts.x | sudo bash -

If you prefer to use the Current release of Node.js, you can run the following command instead:

curl -sL https://rpm.nodesource.com/setup_current.x | sudo bash -

Step 2: Install Node.js from NodeSource Repository

With the NodeSource repository added to your system, you can now install Node.js. This ensures you get the most up-to-date LTS or Current release, depending on which repository you added in the previous step. To install Node.js, execute the following command:

sudo dnf install nodejs

Step 3: Set NodeSource RPM Priority Over Default Node.js (Situational)

To prioritize the NodeSource repository, you need to modify the repository configuration file. The configuration file is usually located in the /etc/yum.repos.d directory. In our case, the file will be nodesource.repo.

First, let’s open the nodesource.repo file with a text editor, such as nano. Run the following command:

sudo nano /etc/yum.repos.d/nodesource.repo

Now, add the following line under the [nodesource] section:

priority=1

This sets the priority of the NodeSource repository to be higher than the default Fedora repository. The lower the priority number, the higher the preference. In this case, the priority value of 1 ensures that the NodeSource repository is preferred over the default Fedora repository, which typically has a default priority value of 99.

After adding the priority line, your nodesource.repo file should look like this:

[nodesource]
name=Node.js Packages for Fedora $releasever - $basearch
baseurl=https://rpm.nodesource.com/<LTS_OR_CURRENT_RELEASE>/fc/$releasever/$basearch
enabled=1
gpgcheck=1
priority=1
...

Make sure to replace <LTS_OR_CURRENT_RELEASE> with either setup_lts.x or setup_current.x, depending on your preference.

Save and close the file. The NodeSource repository will take precedence over the default Fedora repository when installing Node.js.

Proceed with the installation of Node.js as described in Step 2. Your system will now install Node.js from the NodeSource repository, ensuring you can access the latest LTS or Current release.

Section 3: Install Node.js using NVM (Node Version Manager)

This section will discuss how to install Node.js using NVM (Node Version Manager). NVM is an excellent alternative to installing Node.js from the Fedora repository or NodeSource RPM because it provides greater flexibility and control over your Node.js environment. With NVM, you can install and manage multiple versions of Node.js on your system, easily switch between them, and even run different versions for different projects.

NVM is particularly useful for developers working on multiple projects with varying Node.js version requirements or those who need to test their applications against different Node.js versions. Moreover, NVM ensures you can quickly and easily update to the latest LTS or Current releases without affecting other Node.js versions installed on your system.

Step 1: Install NVM

Begin by installing NVM on your Fedora system. Execute the following command to download and run the NVM installation script:

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

or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

After running the script, restart your terminal or run the following command to apply the changes:

source ~/.bashrc

Step 2: Install Node.js using NVM

Now that NVM is installed, you can install Node.js by running the following commands. If you want to install the latest LTS release (v18.16.0 at the time of writing), use:

nvm install --lts

For the latest Current release (v19.9.0 at the time of writing), use:

nvm install stable

Alternatively, you can run:

nvm install node

Once the desired version of Node.js is installed, you can start using it for your development projects. If you need to switch between different Node.js versions, use the nvm use command followed by the version number, like this:

nvm use 18.16.0

With NVM, managing multiple Node.js versions on your Fedora system is simple and efficient, allowing you to work on various projects with ease and confidence.

Step 3: Common NVM Commands

This section will cover more examples of using NVM to manage multiple Node.js versions on your system. These examples will demonstrate switching between different versions, setting a default version, listing installed versions, and more.

Example 1: List Installed Node.js Versions

To list all installed Node.js versions on your system, run the following command:

nvm ls

This command will display a list of installed Node.js versions, with an arrow indicating the currently active version.

Example 2: Switch Between Node.js Versions

As mentioned earlier, you can switch between Node.js versions using the nvm use command. For example, to switch to Node.js version 19.9.0, run:

nvm use 19.9.0

Your system will now use the specified Node.js version for any new terminal sessions.

Example 3: Set the Default Node.js Version

To set a default Node.js version that will be used every time you open a new terminal session, use the nvm alias command. For example, to set Node.js version 18.16.0 as the default, run:

nvm alias default 18.16.0

Now, every time you open a new terminal session, Node.js version 18.16.0 will be automatically activated.

Example 4: List Available Node.js Versions for Installation

If you want to check which Node.js versions are available for installation, you can use the nvm ls-remote command:

nvm ls-remote

This command will display a list of available Node.js versions that you can install using NVM.

Example 5: Uninstall a Node.js Version

To uninstall a specific Node.js version, use the nvm uninstall command followed by the version number. For example, to uninstall Node.js version 19.9.0, run:

nvm uninstall 19.9.0

This command will remove the specified Node.js version from your system.

Example 6: Update the Default Node.js Version and Uninstall the Old One

If you want to update the default Node.js version and remove the old one, you can use a combination of the previously mentioned commands. First, install the new version using nvm install. Then, set the new version as the default using nvm alias. Finally, uninstall the old version using nvm uninstall. For example:

nvm install 19.9.0
nvm alias default 19.9.0
nvm uninstall 18.16.0

These commands will install Node.js version 19.9.0, set it as the default version, and uninstall the old version 18.16.0.

Section 4: How to Remove Node.js from Fedora

In this section, we will discuss the process of removing Node.js from your Fedora system. The steps to follow depend on the method you used to install Node.js, either from the Fedora repository, NodeSource RPM, or using NVM (Node Version Manager).

Step 1: Uninstall Node.js Installed from Fedora or NodeSource

If you installed Node.js from the Fedora Repository or NodeSource, you can uninstall it using the dnf program. Let’s understand the command:

sudo dnf remove nodejs

This command will remove Node.js along with its associated configuration files. It will prompt you to confirm the removal, and after confirmation, it will proceed with the uninstallation.

Step 2: Uninstall Node.js Installed using NVM

If you installed Node.js using the Node Version Manager (NVM), you can uninstall it by following these steps:

2.1: Check the Current Node.js Version

First, check the current version of Node.js installed by running the command:

nvm current

This command will display the active Node.js version on your system.

2.2: Deactivate NVM

Before uninstalling the current version of Node.js, you need to deactivate NVM by running the following:

nvm deactivate

This command will unload the active Node.js version from your current session.

2.3: Uninstall Node.js Version using NVM

Now, run the following command to uninstall a specific version of Node.js installed using NVM:

nvm uninstall <version>

Replace <version> with the version number you want to uninstall. For example, if you want to uninstall Node.js version 19.9.0, you would run:

nvm uninstall 19.9.0

This command will remove the specified Node.js version from your system.

Conclusion: Installing Node.js on Fedora Linux

This guide covered various methods to install Node.js on Fedora Linux, including using the Fedora repository, NodeSource RPM, and Node Version Manager (NVM). Depending on your requirements, you can choose the most suitable method to manage and maintain Node.js versions on your Fedora system. Each method has unique advantages, and understanding the differences will help you decide which approach best fits your needs.

Additional Resources and Links

If you’re looking to learn more about Node.js and Fedora, the following resources can provide valuable information, documentation, and community support:

  • Node.js Official Website: The official Node.js website is the primary source for Node.js documentation, downloads, and updates.
  • Node.js Documentation: Official Node.js documentation contains comprehensive information on various topics, from getting started with Node.js to advanced concepts and API references.
  • Fedora Official Website: The official Fedora website provides downloads, documentation, and community support for Fedora Linux users.
  • Fedora Documentation: The official Fedora documentation contains guides, tips, and tutorials to help you better understand the Fedora operating system.
  • NVM GitHub Repository: The official NVM GitHub repository contains the source code, documentation, and installation instructions for the Node Version Manager.

Share to...