How To Install Node.js on Fedora 36/35/34

Channel: Linux
Abstract: After installation check the installed Node.js version on your Fedora system. node --versionrun the following command to install Node.js on the Fedora

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Latest version node.js dnf repository is maintaining by its official website. This tutorial will help you to install Node.js on Fedora system.

This tutorial contains 3 ways to install Node.js on the Fedora system. Use one of the below options as suitable to you.

  1. Install Node.js from Default Package Repository
  2. Install Node.js from Official Repository
  3. Installing Node.js using NVM
Prerequisites

We assume you already have shell access to your Fedora system with sudo privileged account. Login to your Fedora system and open a terminal.

Method 1 – Install Node.js from Default Package Repository

The Fedora default package repositories contain a stable version of Node.js. It may not be the latest version but it will be a stable release and can be used for working with it.

Open a terminal on your system and type below to install Node.js on Fedora machine:

sudo dnf install nodejs 

Once the installation is completed, you can check the installed Node.js version on your Fedora machine by running the following command.

node -v 
Method 2 – Install Node.js from Official Repository

Node.js official team provides a repository for installing the latest packages for your Fedora system. You can choose between the latest or stable version of Node.js to install on your system. During the time of writing this tutorial, NodeJs 17 is the latest release and Node.js 16 is the stable version available.

Choose one of the below options to configure the Node.js DNF repository on Fedora for the latest version or stable version.

For Latest Release:-

sudo dnf install -y gcc-c++ make 
curl -sL https://rpm.nodesource.com/setup_17.x | sudo -E bash - 

For Stable Release:-

sudo dnf install -y gcc-c++ make 
curl -sL https://rpm.nodesource.com/setup_16.x | sudo -E bash - 

After adding the required repository to your Fedora system, Simply run the below command to install the Node.js on Fedora based on configured repository. This will also install NPM on the Fedora system including other required dependencies.

sudo dnf install nodejs 

After installation check the installed Node.js version on your Fedora system.

node --version 

v16.14.0

To check NPM version:

npm --version 

7.13.0
Method 3 – Install Node.js on Fedora via NVM

NVM is the Node Version Manager used to manage multiple Node.js versions on a single system. Using the NVM, you can install any version of Node.js.

First, install NVM tool on your system by running the following command:

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

Then, reload the system environment using this command. It will set the required environment variables to use nvm on the system.

source ~/.bashrc 

Now, run the following command to install Node.js on the Fedora system. You can change v12.16.2 with any version, you required on your system. You can also install multiple Node.js versions by running the command multiple times.

nvm install v16.14 

For more details and instruction for nvm, follow this tutorial.

Run Demo HTTP Server (Optional)

This is an optional step. If you want to test your node.js install. Let’s create a web server with the 「Welcome Node.js」 text. Create a file demo_server.js

vim http_demo_server.js 

and add the following content

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

Now start the webserver using the command.

node --inspect http_demo_server.js 

Debugger listening on ws://127.0.0.1:9229/5ee4a9ae-a9c8-4cd8-916d-13abe0836b53
For help, see: https://nodejs.org/en/docs/inspector
Server running at http://127.0.0.1:3001/

Web server has been started on port 3001. Now access http://127.0.0.1:3001/ url in browser.

Conclusion

This tutorial helped you to install Node.js on the Fedora Linux system. Additionally provided a small script to create a web server using Node.js.

Ref From: tecadmin

Related articles