CentOS

How to Install and Use Vagrant on CentOS 8

A vagrant is an open-source tool that helps create, maintain and manage virtual environments. Vagrant has an easy-to-use workflow and focuses on automation. It decreases setup time and increases productivity. On Vagrant, it is straightforward to share setups between team members, enabling everyone to have the same setup.

This article provides an extensive guide on how to install Vagrant on CentOS 8. We will also discuss how to create virtual development environments.

Download and install Vagrant on CentOS 8

Go to the official website of Vagrant to check the latest version. The latest version of Vagrant for Linux at the time of writing this article is 2.2.16.

Now fire up the terminal and input the following command to add the vagrant repository on CentOS 8 system:

$ sudo dnf install config-manager --add-repo=https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo

After adding the repository, execute the command given below to install Vagrant on your system:

$ sudo dnf install vagrant -y

You can validate whether the Vagrant installation was successful or not by using the following command once the installation is complete.

$ vagrant --version

Output

Creating a Development Environment Using Vagrant

You can now create virtual development environments as the installation has completed.

To make a development environment, you will need the Virtual Box provider.

If VirtualBox is not installed on your CentOS 8 system, install it by visiting this link.

The next step is to create a new directory for the project. You can use the “mkdir” command to make a new directory:

Remember to change “test-project” with the actual name of the project.

$ mkdir ~/test-project

Navigate to the newly created directory:

$ cd ~/test-project

Use the “vagrant init” command followed by a box name to create a new Vagrantfile.

$ vagrant init ubuntu/bionic64

Output

Vagrantfile is a configuration file that handles the virtual machine’s configuration and defines how it is provisioned.

As an example, here, we’ve used the ubuntu/bionic64 box.

Boxes are provider-specific package formats for Vagrant development environments. The list of publicly available Vagrant Boxes can be found in this catalog.

Please open the Vagrantfile in any text editor and make the required modifications. Vagrantfile can be opened and edited with a simple nano text editor.

$ sudo nano Vagrantfile

To make a new virtual machine use the “vagrant up” command. The machine will have the same configuration as specified in the Vagrantfile.

$ vagrant up

Output

Vagrant creates the directory of the project at /vagrant on the virtual machine. This enables you to work on your project files from your host machine.

Stop a Vagrant Virtual Machine

You can use the “vagrant halt” command to stop the virtual machine once your work is complete:

$ vagrant halt

Restart a Vagrant Virtual Machine

If you want to restart the virtual machine, use the following command:

$ vagrant reload

Suspend a Vagrant Virtual Machine

If you want to stop the virtual machine while preserving its state, use the “suspend” command:

$ vagrant suspend

Destroy a Vagrant Virtual Machine

If you want to destroy the virtual machine, use the following command:

$ vagrant destroy

This command will also delete all the resources associated with that particular virtual machine.

Conclusion

A vagrant is a potent tool that many specialists use. The fact that It does not have any great alternatives increases its significance even more. This article has provided a detailed guide on the installation process of vagrant. It also shows the steps we can use to create virtual machines on CentOS 8.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.