Read in 3 minutes
How to install Vagrant on CentOS 7
Vagrant is an open source command line tool for building and managing virtual machine environments. By default Vagrant can provision machines on top of VirtualBox, Hyper-V and Docker but many other providers such as Libvirt (KVM), VMware and AWS can be installed via the Vagrant plugin system.
Vagrant is mostly used by developers to easily set up a development environment, that matches the production environment.
In this tutorial we will walk you through installing Vagrant on CentOS 7 systems. We’ll be using the VirtualBox provider, which is the default provider for Vagrant.
Ensure that you have met the following prerequisites before continuing with this tutorial:
Installing Vagrant on CentOS
At the time of writing this article, the latest stable version of Vagrant is version 2.2.0. Before continuing with the next step visit the Vagrant downloads page and check if there is a new version of Vagrant available.
Use the following command to install Vagrant on you CentOS machine:
sudo yum install https://releases.hashicorp.com/vagrant/2.2.0/vagrant_2.2.0_x86_64.rpm
To verify that the installation was successful run the following command which will print the Vagrant version:
The output should look something like this:
Getting Started with Vagrant
Now that Vagrant is installed on your CentOS system we will show you how to create a development environment which is the most common use case.
The first step is to create a directory which will be the project root directory and hold the Vagrantfile file. Vagrantfile is a Ruby file that describes how to configure and provision the virtual machine.
Create the project directory and switch to it with:
mkdir ~/my-vagrant-project cd ~/my-vagrant-project
The next step is to initialize a new Vagrantfile using the
vagrant init command and specify the box you want to use.
Boxes are the package format for the Vagrant environments and are provider-specific. You can find a list of publicly available Vagrant Boxes on the Vagrant box catalog page.
In this example we will use the
ubuntu/bionic64 box. Run the following command to initialize a new Vagrantfile:
vagrant init ubuntu/bionic64
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.
Now we can run the
vagrant up command which will create and configure the virtual machine according to the Vagrantfile.
==> default: Configuring and enabling network interfaces... default: SSH address: 192.168.121.24:22 default: SSH username: vagrant default: SSH auth method: private key ==> default: Rsyncing folder: /home/linuxize/Vagrant/my-vagrant-project/ => /vagrant
As you can see from the output above Vagrant also mounts the project directory at
/vagrant in the virtual machine which allows you to work on your project’s files on your host machine.
To ssh into the virtual machine simply run:
You can stop the virtual machine with the following command:
This command stops the running machine if it is running and destroys all resources that were created during the creation of the machine:
You have learned how to install and use Vagrant on your CentOS 7 machine. We have also shown you how to create a basic development environment.
To find more information about Vagrant visit the official Vagrant documentation page.
If you have any question, please leave a comment below.