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.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/word-image-111.png60e8c577c6cbd.jpg" data-lazy- height="473" src="data:image/svg xml,” width=”841″>

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

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/word-image-112.png60e8c57850f64.jpg" data-lazy- height="76" src="data:image/svg xml,” width=”729″>

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

$ sudo dnf install vagrant -y

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/word-image-113.png60e8c578e3443.jpg" data-lazy- height="325" src="data:image/svg xml,” width=”729″>

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

Output

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/word-image-114.png" data-lazy- height="58" src="data:image/svg xml,” width=”404″>

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.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/word-image-115.png60e8c57978cf6.jpg" data-lazy- height="40" src="data:image/svg xml,” width=”424″>

Navigate to the newly created directory:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/word-image-116.png60e8c57a0afd6.jpg" data-lazy- height="40" src="data:image/svg xml,” width=”412″>

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

$ vagrant init ubuntu/bionic64

Output

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/word-image-117.png60e8c57abb76b.jpg" data-lazy- height="111" src="data:image/svg xml,” width=”597″>

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.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/word-image-118.png60e8c57b25d31.jpg" data-lazy- height="538" src="data:image/svg xml,” width=”752″>

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

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:

Restart a Vagrant Virtual Machine

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

Suspend a Vagrant Virtual Machine

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

Destroy a Vagrant Virtual Machine

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

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

<img alt="" data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/7011409B3A384F43A8417D1DAC68D179-150×150.jpg60e8c57b337cb.jpg" height="112" src="data:image/svg xml,” width=”112″>

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.