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 the 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.
- Install Node.js from Default Package Repository
- Install Node.js from Official Repository
- 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 the Fedora Linux system:
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_18.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
Once the installation is finished, check for the installed Node.js version:
node --version
v18.7.0
To check the 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 the 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/
The 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.
13 Comments
thank you man!
Thank you so very much! Helped a lot. (fedora 35)
This was exceptionally helpful. Thank you.
Worked great on a new Fedora 31 install, thanks!
node –version
v12.10.0
Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0
Dear Rahul,
Just one annotation, need an space beetween –inspect and http_demo_server.js, actually is like this:
node –inspecthttp_demo_server.js
should be
node –inspect http_demo_server.js
Thanks a lot for this great guide.
Thanks Guillermo
`node –debug` and `node –debug-brk` are invalid. Please use `node –inspect` and `node –inspect-brk` instead.
Update the article
Thanks, Tutorial has been updated
This was extremely helpful,
thanks much, RAHUL.
Following those instructions “For Latest Release” it installs Node v10.15.3 and NPM 6.4.1. on fresh Fedora 30 which is not what i want. So instructions are useless.
These instructions don’t work for Fedora 30 since Node.js isn’t released for it yet. The issue is being tracked here: https://github.com/nodesource/distributions/issues/842
To start the web server, you are using: node –debug http_demo_server.js
But ‘ –debug’ is deprecated and one must use ‘–inspect’
So the command will be : node –inspect http_demo_server.js
You can just use “sudo dnf install nodejs” since Fedora 29