Vagrant install Nodejs on Rocky Linux

#Introduction

In this tutorial, How to use Vagrant install Nodejs on Rocky Linux / RHEL Linux.

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 Environment for Vagrant install Nodejs

  • Host OS: Window 11
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell

Vagrant directory and files will look like as below:

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 content script is as below:

#!/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 "##########################"

Create 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

Vagrant install Nodejs on Rocky Linux

vagrant up

To connect to Node Server.

vagrant ssh nodeserver

The output terminal as below

Vagrant install Nodejs on Rocky Linux

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

Vagrant check Nodejs on Rocky Linux

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

Vagrant destroyNodejs on Rocky Linux

Conclusion

You have to use the Vagrant install Nodejs on Rocky Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.