Greetings and salutations. Our guide today will focus on Vagrant. Vagrant is an open-source tool that helps developers to create and configure lightweight and easy-to-reproduce development environments. Vagrant also makes the development environment portable across teams as well as managing virtual machine environments. Simply put, Vagrant is a tool for building and maintaining virtual machine environments in a single workflow.
Vagrant isolates the dependencies and their configurations in a single disposable, consistent environment without sacrificing your existing tools. It is considered the easiest and fastest way to create a virtualized environment. Vagrant uses a declarative configuration file where the developer defines all the application’s requirements and builds them through a consistent workflow. This will in return increase the production parity as production environments can easily be mirrored where users can use the same operating systems, packages, configurations, etc while maintaining their favorite text editors.
Vagrant manages Virtual machine-based development environments. Vagrant Boxes are pre-built base images that can be imported into Vagrant as a starting point.
Why Vagrant?
A Vagrant is an automation tool used by different personnel including developers, operators, designers, and everyone. This is due to the following reasons:-
- Developers prefer Vagrant because of its ability to isolate dependencies and their configurations in a single disposable, consistent environment without sacrificing the tools they prefer to use e.g text editors, browsers, etc. A developer simply creates a vagrantfile and then runs the vagrant up command to configure and install everything for the developer. Other developers can use the same file across multiple platforms e.g Linux, macOS, and Windows to create their applications using the same dependencies and same configurations.
- For Operations engineers / DevOps engineers vagrant will provide a disposable environment and consistent workflow for developing and testing infrastructure management scripts. Hence shell scripts, cookbooks, Chef, puppet modules, etc can be tested in virtualized environments eg VMware, Virtualbox, etc on Cloud eg AWS, etc using the same workflow.
- For Designers Vagrant will automatically set up everything required for web applications so that the designer can concentrate on design work.
- Vagrant is designed for Everyone.
Interactions with Vagrant are through a command-line interface. The vagrant command brings up the vagrant interface and shows the help utilities i.e all the commands available for use with vagrant. Running the vagrant command with the -h option will print out help regarding a particular command. Vagrant supports bash and zsh and gives the ability to autocomplete commands. These are enabled using the command vagrant autocomplete install –bash –zsh
Vagrant’s main use case is for provisioning development environments by maintaining consistency between environments by using unified workflows to enforce consistency across platforms. In this article, we will learn how to Install and Use Vagrant on Oracle Linux 9.
How To Install and Use Vagrant on Oracle Linux 9
With the brief preamble above, let’s fold our sleeves and dive right in. Let’s begin by listing the prerequisites.
Setup Pre-requisites
For a successful installation, your system should meet the following requirements:-
- Software requirements – ensure you have a VirtualBox, VMware, proxmox, etc, and Hyper-V for windows users.
- RAM – minimum of 4GB
- CPU Cores – 2+
- Storage of 4GB and above.
- Stable internet connection.
- BIOS Virtualization – Intel VT-x, AMD-V. Ensure BIOS is turned on.
Let’s prepare our system by ensuring that the system is up to date.
sudo dnf update && sudo dnf upgrade -y
Step 1: Ensure virtualization is enabled in your system
You must ensure that you have a hypervisor installed in your system. If it is not installed, see our guides:
For this guide, I will use VirtualBox 7.0 hypervisor.
Navigate to Virtualbox.org and download the latest virtual box release. As of this writing, the latest release is VirtualBox 7.1.x. The summarized steps for VirtualBox installation are as below.
#Install dependencies
sudo dnf install epel-release wget -y
sudo yum install kernel-uek-devel-$(uname -r) gcc make perl bzip2 dkms
#Install VirtualBox
wget https://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
sudo mv virtualbox.repo /etc/yum.repos.d/
Install VirtualBox:
sudo dnf install VirtualBox-7.0
Validate that VirtualBox is successfully installed in your Oracle Linux machine.
$ lsmod | grep vbox
vboxnetadp 28672 0
vboxnetflt 40960 0
vboxdrv 638976 2 vboxnetadp,vboxnetflt
To ensure that CLI is working, type the following commands:
$ vboxmanage --help
$ vboxmanage --version
7.0.4r154605
I will check if Virtualization is enabled by running the command below.
$ lsmod | grep kvm
kvm_intel 385024 0
kvm 1122304 1 kvm_intel
irqbypass 16384 1 kvm
The name of the hypervisor installed in my system is kvm_intel
and I am good to go. The VirtualBox is successfully installed in your system.
Step 2: Download and install Vagrant
Vagrant is distributed as a binary package. Navigate to the Vagrant latest releases download page for the latest package. It is supported across macOS, Linux, and Windows. Development environments managed by vagrant can run on local virtualized platforms such as VirtualBox or VMWare, in the cloud via AWS or OpenStack, or in containers such as Docker, or LXC containers.
Begin installation by installing the required dependencies. Run the command below.
sudo yum install -y yum-utils
Then add the hashicorp repository.
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
Proceed to install the Vagrant package with the following command.
sudo dnf install vagrant
To Verify the version installed, run the command:
$ vagrant version
Installed Version: 2.3.4
Latest Version: 2.3.4
You're running an up-to-date version of Vagrant!
To see help commands that can be used together with vagrant, run the command:
$ vagrant
## or ##
$ vagrant --help
Step 3: Adding and starting Vagrant Box
Begin by creating a working directory for your development project and within the directory issue the following commands.
mkdir demo
cd demo
Next, create a vagrantfile that defines the specific virtual environment to be deployed to the VirtualBox. Run this command.
# Command Syntax
$ vagrant init oraclelinux/{release} <box json url>
Run the command as shown below.
$ vagrant init oraclelinux/9
#The command output.
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
To see the details of the Vagrantfile, issue the command:
more Vagrantfile
To start the environment, run the command:
$ vagrant up
#sample output
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'oraclelinux/9' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'https://oracle.github.io/vagrant-projects/boxes/oraclelinux/9.json'
default: URL: https://oracle.github.io/vagrant-projects/boxes/oraclelinux/9.json
==> default: Adding box 'oraclelinux/9' (v9.1.389) for provider: virtualbox
default: Downloading: https://yum.oracle.com/boxes/oraclelinux/ol9/OL9U1_x86_64-vagrant-virtualbox-b389.box
default: Calculating and comparing box checksum...
==> default: Successfully added box 'oraclelinux/9' (v9.1.389) for 'virtualbox'!
==> default: Importing base box 'oraclelinux/9'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'oraclelinux/9' version '9.1.389' is up to date...
==> default: Setting the name of the VM: demo_default_1672236475923_51308
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:
https://www.virtualbox.org/manual/ch04.html#sharedfolders
This option can be disabled globally with an environment variable:
VAGRANT_DISABLE_VBOXSYMLINKCREATE=1
or on a per folder basis within the Vagrantfile:
config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => /home/jil/demo
During the deployment, the vagrant creates the VM, assigns network interfaces, and creates the forwarding port for SSH. The default port is 2222 and if that port is in use, Vagrant will detect it and dynamically use a different port. Vagrant also picks any proxy settings if configured from your host and ensure the Guest Additions are up to date for VirtualBox. If the Guest Additions are not at the same version as the host, Vagrant downloads the necessary packages and updates the software automatically.
Step 4: Connect to vagrant environment
Our VM is now fully set up. We will now connect to the environment via SSH. Execute the command below:
$ vagrant ssh
Welcome to Oracle Linux Server release 9.1 (GNU/Linux 5.15.0-3.60.5.1.el9uek.x86_64)
The Oracle Linux End-User License Agreement can be viewed here:
* /usr/share/eula/eula.en_US
For additional packages, updates, documentation and community help, see:
* https://yum.oracle.com/
[vagrant@localhost ~]$
Once you have successfully connected, test your setup by issuing the following commands.
$ hostname
localhost.localdomain
$ cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.1"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.1"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.1"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:1:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.1
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.1
From the output, our VM is running on Oracle Linux Server 9.1
To check the Network Interface assigned to the VM, issue the command below.
$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:d3:cc:9c brd ff:ff:ff:ff:ff:ff
altname enp0s3
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute eth0
valid_lft 84913sec preferred_lft 84913sec
inet6 fe80::2c9c:86a0:7ee3:a39b/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Click exit to jump out of the VM.
To Launch the VM, navigate to Activities >> Search Oracle VM VirtualBox
To update an Oracle Linux box run the following command.
1 ) Check available updates:
$ vagrant box outdated --global
* 'oraclelinux/9' for 'virtualbox' (v9.1.389) is up to date
2 ) To update a Vagrant box to the latest available version:
$ vagrant box update --box oraclelinux/9
Checking for updates to 'oraclelinux/9'
Latest installed version: 9.1.389
Version constraints: > 9.1.389
Provider: virtualbox
Box 'oraclelinux/9' (v9.1.389) is running the latest version.
My output shows am running on the latest available version.
3 ) To perform a graceful shutdown of the VM:
$ vagrant halt
4 ) When you are done with the project and wish to kill your VM, run the command:
$ vagrant destroy
Step 5: Vagrant configuration file
The main components of a Vagrant configuration file are as below.
The Vagrantfile created by the init command has very key information. This is where you do all your configurations.
Some key configurations include the following:
- config.vm.box —-> This is the Operating System that you will be deploying.
- config.vm.provider —-> This is VirtualBox in our case
- config.vm.network —-> This defines how your host machine sees your box.
- config.vm.synced_folder —-> This defines how you access files from your computer
- config.vm.provision ——> This defines what we want to setup
This is what you should master in a Vagrantfile configuration file.
Step 6: Configure your VM
To edit your VM settings, launch the VM and change the default settings. By default, your VM will default with the following settings.

To change the default settings, click Settings and make your changes. Then power on your VM.
Wrapping up
That marks the end of our guide today. Vagrant is a very important tool for Virtual Machine management. It makes VM deployment very easy. It saves the System Admin the hustle of having to download the ISO files and then manually build the VM. With Vagrant, you don’t need to master the CLI commands for different providers, Vagrant handles that for you. Again, the Vagrantfile has easy-to-understand text files. The Administrator can create as many Vagrant instances using the same Vagrantfile. In addition, the developer can deploy/destroy multiple development environments in a couple of minutes.
Read more: