Table of Contents
Introduction
Welcome to this tutorial, where we’ll guide you through the process of install Nodejs on Rocky Linux or RHEL Linux using Vagrant. Node.js is a powerful runtime that allows you to run JavaScript on the server side, making it a crucial component for various web applications and development projects. With the help of Vagrant, we’ll simplify the installation process and ensure a smooth setup on your Rocky Linux or RHEL Linux environment.
What does Nodejs mean?
Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. quote from Wikipedia.
My Setup for Installing Node.js with Vagrant
- Host OS: Window 11
- Vagrant version: 2.2.18
- Vagrant provider: VirtualBox
- Boxes Vagrant: rockylinux/8
- Terminal/PowerShell
The structure of the Vagrant directory and files will appear as follows:
C:\MYDATA\VAGRANT_VMS\PROJECTS\VAGRANT\ROCKY-NODEJS
│ Vagrantfile
│
├───sample-app
└───shell
init-nodejs.sh
I created an init-nodejs.sh
script to Install Node.JS from Nodesource Repositories or Install Node.JS from Rocky Linux AppStream Repositories.
The script content is as follows:
#!/bin/bash
# Update your system
sudo yum update -y
#Tools
sudo dnf install -y git unzip net-tools
# Install Node.JS from Rocky Linux AppStream Repositories
#sudo dnf module list nodejs -y
#sudo dnf module install nodejs:14
#sudo dnf install nodejs
#node -v
#npm -v
# Install Node.JS from Nodesource Repositories
# curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - # For ubuntu Server
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo dnf install nodejs -y
# Check version
node -v
npm -v
echo "##########################"
echo "Run npm install and then run app..."
echo "##########################"
#mkdir sample-app
#cd sample-app
#sudo npm install
#sudo forever start server.js
echo "##########################"
echo "Success! Navigate to localhost..."
echo "##########################"
Set Up a Virtual Machine
Navigate to my working directory
cd Rocky-Nodejs
vagrant init rockylinux/8
Configure the Virtual Machine
Edit the Vagrantfile and paste the content below
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "rockylinux/8"
config.ssh.insert_key = false
config.vbguest.auto_update = false
# Uncomment this if you want to link to a shared folder (e.g. if you are running source control and want to link it to Vagrant)
config.vm.synced_folder "./sample-app", "/home/vagrant/sample-app", create: true, group: "vagrant", owner: "vagrant"
config.vm.define "nodeserver" do |nodeserver|
nodeserver.vm.hostname = "devopsroles.com"
nodeserver.vm.network "private_network", ip: "192.168.4.4"
nodeserver.vm.network "forwarded_port", guest: 3000, host: 3000
nodeserver.vm.provision "shell",
path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-Nodejs\\shell\\init-nodejs.sh"
end
end
Use Vagrant install Nodejs on Rocky Linux
vagrant up
To connect to Node Server.
vagrant ssh nodeserver
The output terminal is below

Check the Nodejs version that you have installed with the help of the following picture.

After you don’t use it, You delete Node Server.

Conclusion
To install Node.js on Rocky Linux, utilize Vagrant. I hope you find this information helpful. Thank you for visiting the DevopsRoles page!