Blog

How to install CentOS or Ubuntu in Vagrant using the Shell script?

Linux / Shell Script

How to install CentOS or Ubuntu in Vagrant using the Shell script?

Vagrant simplifies the process of setting up development environments by producing a compatible workflow beyond different operating systems and virtualization platforms. Vagrant is an open-source tool for building and managing virtualized development environments.

The below example shell script is used to install Vagrant on both CentOS and Ubuntu systems. The script will determine the operating system and execute the appropriate commands for installation.

#!/bin/bash
## Install the Vagrant package either in your CentOS 7/8 or Ubuntu 18.04 >
if [ -f /etc/redhat-release ]; then
  sudo yum update
  sudo yum -y install kernel-headers kernel-devel binutils glibc-headers glibc-devel font-forge wget
  wget https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.rpm
  sudo rpm -i vagrant_2.2.19_x86_64.rpm
  vagrant --version
fi

if [ -f /etc/lsb-release ]; then
  sudo apt-get update
  wget https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.deb
  sudo apt install ./vagrant_2.2.19_x86_64.deb
  vagrant --version
fi
## Execute the vagrant comamnd
vagrant up

Save the above script to a file, for example installvagrant.sh and then make it executable:

chmod +x install_vagrant.sh

Execute the script with superuser privileges:

sudo ./install_vagrant.sh

The script will identify the operating system and progress with the relevant installation commands for either CentOS or Ubuntu.

Spread the love

Leave your thought here

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