Node.js is a free, open-source, cross-platform JavaScript runtime environment. It is a backend that runs on Linux, Windows, and Mac. It is used to build scalable server-side and networking applications. It provides an event-driven and asynchronous environment to build different applications such as command line, web, chat, and more.

This post will show you how to install Node.js on Fedora.

Install Node.js Using Default Repo

By default, Node.js is available in the Fedora default repo. You can install it with the following command.

dnf install nodejs

After the installation, you can verify the Node.js version with the following command.

node -v 

Output:

v14.19.0

To remove the Node.js from your server, run the following command.

dnf remove -y nodejs npm

Install Node.js Using Node Source

First, install all required dependencies using the following command.

dnf install -y gcc-c++ make

Next, add the Node source repo with the following command.

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

After that, install Node.js with the following command.

dnf install nodejs

You can verify the Node.js version with the following command.

node -v

Output:

v18.19.0

Now, remove Node.js using the following command.

dnf remove -y nodejs npm

Install Node.js Using NVM

NVM provides a simple and easiest way to install multiple versions of Node.js via the command line.

First, install Node.js with the following command.

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

Next, activate the NVM environment with the following command.

source ~/.bashrc 

Next, use the following command to install Node.js version 16.14.

nvm install v16.14 

Output:

Downloading and installing node v16.14.2...
Downloading https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.xz...
################################################################################################################################################################# 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.14.2 (npm v8.5.0)
Creating default alias: default -> v16.14 (-> v16.14.2)

You can now verify the Node.js version with the following command.

node -v 

Output:

v16.14.2

Create a Sample App Using Node.js

First, create an app.js file with the following command.

nano app.js

Add the following code.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Node.js is installed on Fedora');
}).listen(3001, "0.0.0.0");
console.log('Server running at http://0.0.0.0:3001/');

Next, run the Node.js application using the following command.

node --inspect app.js

You will get the following output.

Debugger listening on ws://127.0.0.1:9229/a9c46826-65d4-4088-83ae-fbd1e917832a
For help, see: https://nodejs.org/en/docs/inspector
Server running at http://0.0.0.0:3001/

Now, open your web browser and access the Node.js application using the URL http://your-server-ip:3001. You should see your sample application on the following screen.

Node.js dashboard

Conclusion

This tutorial explained how to install Node.js using different ways on Fedora. We also showed you how to create and run a Node.js application. You can now try Node.js on VPS hosting from Atlantic.Net!