How to install Node.js and npm in Fedora

Endrit Qerreti

Endrit Qerreti

In this tutorial, you will learn how to install Node.js and npm in Fedora.

Node.js can be installed in Fedora easily via dnf package manager.

In this tutorial, we'll be installing Node.js and npm in Fedora, via the official Node.js module nodejs, which is available in the default repository of Fedora, and via Node version manager (Nvm).

Method 1: Install Node.js via dnf

In this method, we'll be installing Node.js in Fedora, via the default package manager dnf

Step 1 - Update your machine

Since we'll be downloading nodejs module from the Appstream repository in Fedora, we need to update our system to ensure that we can download the latest packages from this repository.

To update package database in Fedora, you can use dnf.

To do so, simply run the command below.

sudo dnf update -y

Step 2 - Install Node.js

Now that the package database in your system is up to date, proceed to install Node.js in your Fedora machine.

Installing Node.js is quite simple, and you can easily install it by using the dnf package manager, as Node.js package is available in the Fedora repositories.

sudo dnf install nodejs

💡
Note: The command above, will install the latest version of the Node.js package that is available in the Fedora repository. If you want to install a custom version of Node.js in Fedora, you can do so by using the nvm script.

Step 3 - Verify Node.js Installation

By now Node.js should be installed in your Fedora machine. Before starting to use Node.js in your system, ensure that Node.js was installed correctly

Check Node.js version, to verify that you can run Node.js

node -v

Method 2: Install Node.js via nvm

In this method, we'll be installing Node.js in Fedora, via Node version manager script. Nvm allows you to install any version of Node.js in your Fedora machine.

Step 1 - Install Nvm

First, you need to download the Nvm script from the official Github repository of Nvm.

1) To download Nvm you can use curl.

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

2) Next, once nvm script is downloaded, you need to make the installer executable, so that you can run it.

chmod +x install.sh

3) Next, install Nvm by running the installer.

./install.sh

Step 2 - Add nvm to PATH

Now you need to add nvm to your ~/.bashrc file, in order to be able to use nvm in you terminal.

To add nvm to your PATH, simply run the command below.

source ~/.bashrc

Step 3 - Choose Node.js version

Nvm lets you install any version of Node.js that is available. To see what Node.js versions are available for downloading, simply run the command below.

nvm ls-remote

Next, choose the Node.js version that you want to install.

For example, to install the LTS version of Node.js via nvm, run the command below.

nvm install --lts

If you want to install a specific custom of Node.js, then you can do so by setting the version of Node.js

For example, to install Node.js version 18 LTS, run the command below.

nvm install 18.19.0

Node.js should be installed now in your Fedora machine.

Step 4 - Verify Node.js installation

To verify that Node.js was installed correctly via nvm, you need to switch to the Node.js version that you chose.

For example, we installed Node.js 18, so to switch to Node.js 18, run the command below.

nvm use 18.19.0

Next, we need to run node version command to verify that we can run that Node.js version.

node -v

As you can see, we are now running Node.js v18.19.0, which means the installation was done correctly,

Uninstalling Node.js in Fedora 39

You can easily uninstall Node.js in Fedora 39, depending the method you used to install Node.js.

If you installed Node.js via the first method, by using dnf package manager, then you can easily uninstall Node.js via dnf.

sudo dnf remove nodejs -y

If you Installed Node.js via nvm, then you need to use nvm to uninstall Node.js.

To do so, simply run the command below.

nvm uninstall 21.5.0

Conclusion

In this tutorial, you learned how to install Node.js in Fedora workstation 39, via two different methods.

In the first method, we installed Node.js via dnf package manager, by downloading the official Node.js package from the Fedora repositories.

In the second method, we installed Node.js via Node version manager script.