After stumbling upon several guides still describing a Vagrant installation via a RubyGem – which is no longer supported – the following article was created and will provide a quick setup guide on how to setup Vagrant on CentOS 7. All commands used in this guide are executed having root permissions.

Setting up VirtualBox as your Vagrant Provider

Since Vagrant is a utility to manage the lifecycle of virtual machines but doesn’t provide them it relies on providers. As described here Vagrant supports different providers by default such as  VirtualBoxHyper-V, and Docker. Due to the wide availability of VirtualBox it will be used in this guide.

In order to install VirtualBox we first need to add the VirtualBox repository:

cd /etc/yum.repos.d
yum install -y wget
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo

Because the installation of VirtualBox will require building kernel modules DKMS – Dynamic Kernel Module Support – from the EPEL repository will be installed first:

yum -y install epel-release
yum -y install dkms

In order to find the latest available VirtualBox version execute:

yum provides VirtualBox

and install via:

yum -y install VirtualBox-5.1-5.1.22_115126_el7-1.x86_64

Installing Vagrant

The latest Vagrant packages are available here. With a simple:

yum install https://releases.hashicorp.com/vagrant/1.9.6/vagrant_1.9.6_x86_64.rpm

the installation is completed in seconds.

Setting up your project environment

Vagrant projects are managed via Vagrantfiles. In order to start a new project create a dedicated folder and execute Vagrant init which will automatically create a new Vagrantfile:

mkdir Test_Project
cd Test_Project/
vagrant init

Now that we have our environment set up it is time to add a new base image. A variety of images – also called boxes – are available at https://app.vagrantup.com. We will add the latest Ubuntu Image to our boxes with:

vagrant box add ubuntu/xenial64

After the box was added locally we need to change the Vagrantfile which got created before. By changing the parameter config.vm.box from base to ubuntu/xenial64 Vagrant is configured to run the box we added previously.

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/xenial64"
end

Starting your  machine

Now that everything is set up the new machine is started with:

vagrant up

and is accessible by ssh executing:

vagrant ssh

The machine can be stopped with:

vagrant halt

Note: If you can not connect via ssh because you are asked for a password it might be related to: https://bugs.launchpad.net/cloud-images/+bug/1569237. You can switch to ubuntu/trusty64 by deleting your current Vagrantfile:

rm Vagrantfile

adding the ubuntu/trusty64 box:

vagrant box add ubuntu/trusty64

and create a new Vagrantfile containing a proper config.vm.box parameter:

vagrant init ubuntu/trusty64

2 comments

Comments

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.