This post is about installing a useful development tool to play with systems and configurations in a virtualized environment on your fingertips. Want to test your WordPress with a completely differnt web- and database server? Maybe running a proxy in the front?
Vagrant helps you to setup such systems on virtual machines so you can give it a test. Thanks to abstraction via Puppet or Chef, you can deploy these setups later on for hosting. But you can think of smaller scale as well, for example, to have an ideally same (read: as close as practicable possible) environment for development as you have in production. Virtualization helps here and Vagrant makes this more or less straight forward. See Why Vagrant?.
This is just a rather straight forward post about getting Vagrant onto your Fedora system. This follows Getting Started with Vagrant from the projects documentation on their homepage.
For the intial setup, consider to have some bandwidth and time available. The process is straight forward but up to the initial virtual machine at the end, some data has to be downloaded which takes it’s time.
Check if you have got Virtualbox installed:
$ sudo yum list virtualbox Loaded plugins: langpacks, presto, refresh-packagekit Available Packages VirtualBox.x86_64 4.2.4-1.fc17 rpmfusion-free-updates
As it’s not installed, let’s install it:
$ sudo yum install VirtualBox ... Resolving Dependencies --> Running transaction check ... ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: VirtualBox x86_64 4.2.4-1.fc17 rpmfusion-free-updates 20 M Installing for dependencies: kmod-VirtualBox-3.6.5-1.fc17.x86_64 x86_64 4.2.4-2.fc17.1 rpmfusion-free-updates 183 k Transaction Summary ================================================================================ Install 1 Package (+1 Dependent package) Total download size: 20 M Installed size: 73 M Is this ok [y/N]:
As the dependency listing shows it will install also a Kernel Driver Module (kmod) for the software (See: What is the difference between an ‘akmod’ and ‘kmod’? for a snappy overview).
What follows is the typical download and install. You will see the “Complete!” at the end. Let’s verify the install:
$ VBoxManage --version
This will reveal some information about that the kernel module is not yet initialized:
WARNING: The vboxdrv kernel module is not loaded. Either there is no module available for the current kernel (3.6.5-1.fc17.x86_64) or it failed to load. Reboot the computer or load the kernel module by executing '/etc/sysconfig/modules/VirtualBox.modules' (as root) You will not be able to start VMs until this problem is fixed.
and finally the version at the last line:
The warning is logic: The computer did not reboot yet, so after running the package manager, the kernel driver module has not been initialized.
Doing as suggested will enable it straight away:
$ sudo /etc/sysconfig/modules/VirtualBox.modules $ VBoxManage --version 4.2.4_RPMFusionr81684
This was already the first step, VirtualBox is installed and ready to run.
Let’s prepare a subdirectory in the homedir to operate from:
$ mkdir vagrant-setup $ cd vagrant-setup
Then the download (long line), the file is about 15 MB so depending on your bandwith takes a little moment (for me it was @ varying speeds within a minute 20):
curl -O http://files.vagrantup.com/packages/be0bc66efc0c5919e92d8b79e973d9911f2a511f/vagrant_1.0.5_x86_64.rpm
After downloading the package is ready for install – which needs root:
$ sudo rpm -i vagrant_1.0.5_x86_64.rpm
After a short moment in time you have got your prompt back. As Vagrant is commandline based, it is the
vagrant command. But you have to put it into your
The path is
Edit .bash_profile Path
Because I’d like to have it also after reboot, I place it into my
$HOME/.bash_profile file. You can skip this step if you do not like to do this now, just go to the next horizontal line.
$ ls -l /opt/vagrant/bin total 4 -rwxr-xr-x. 1 root root 1226 Sep 22 05:11 vagrant $ vi $HOME/.bash_profile
Changing the existing PATH line by adding the path at the end:
write the buffer and quit. This is now saved.
Left is to give the current shell the path to the
vagrant command, so it is available in the current session:
$ echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/hakre/bin PATH=$PATH:/opt/vagrant/bin
And now you’ve got Vagrant installed. You can verfiy this by just entering the
vagrant command, it should show you something similar to this:
$ vagrant -v Vagrant version 1.0.5
Your First Vagrant Virtual Environment
This is the step outline in the Getting Started with Vagrant document. Let’s try it if it works:
$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box [vagrant] Downloading with Vagrant::Downloaders::HTTP... [vagrant] Downloading box: http://files.vagrantup.com/lucid32.box [vagrant] Progress: 3% (9438840 / 261417472)
This can take it’s time. The perfect time to brew a coffee and fetch some sweets from the bakery.
[vagrant] Extracting box... [vagrant] Verifying box... [vagrant] Cleaning up downloaded box...
Finnaly the download is done. Let’s initialize the new box:
$ vagrant init lucid32 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.
Vagrant tells you nicely what is going on and even better, how to go on:
$ vagrant up [default] Importing base box 'lucid32'... [default] The guest additions on this VM do not match the install version of VirtualBox! This may cause things such as forwarded ports, shared folders, and more to not work properly. If any of those things fail on this machine, please update the guest additions and repackage the box. Guest Additions Version: 4.2.0 VirtualBox Version: 4.2.4 [default] Matching MAC address for NAT networking... [default] Clearing any previously set forwarded ports... [default] Forwarding ports... [default] -- 22 => 2222 (adapter 1) [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] Booting VM... [default] Waiting for VM to boot. This can take a few minutes. [default] VM booted and ready for use! [default] Mounting shared folders... [default] -- v-root: /vagrant
And that is your first virtual machine setup via Vagrant. For a first orientation so that you see is on:
$ VBoxManage list -l vms
And that’s it. You now have installed Vagrant and your first little box up and running.