Install Vagrant on Fedora 27 and 28
Content of post.
The Vagrant is a tool of command line(CLI) that abstracts the complexity of main virtualizers available and allow us to create virtual machines in a way extremely simple, for use it just create the manifest file and from this file a virtual machine will provided with all what we need configured, therefore let’s see how to install it on Fedora.
Requirements
For Vagrant works is necessary have installed some virtualization software, you can know which are supported here, another requirement is that your computer needs to be able to access another by SSH.
This tutorial will use the VirtualBox for virtualization, case you don’t have some requirements and not know how to install it you can follow this tutorial to install VirtualBox and this one to install and configure the SSH.
Install Vagrant
With the VirtualBox and OpenSSH installed we can proceed with download and installation, for it you need to copy and run the text below on your terminal.
wget https://releases.hashicorp.com/vagrant/2.1.1/vagrant_2.1.1_x86_64.rpm && \
sudo dnf install -y ./vagrant*.rpm && \
rm vagrant_*.rpm*
The Vagrant by default not uses conventional installation images, those that you access the site of your Linux distribution preferred, make the download and install on you machine or server, instead those images the Vagrant uses the boxes, basically Vagrant boxes are images derived from official distributions, where everything that not is helpful or essential for Vagrant is dropped, anyone can create own boxes, you can find some boxes compatible with VirtualBox here.
For provide a virtual machine the Vagrant uses the file Vagrantfile where stay all details about the provisioning, for example: shared files, amount of RAM memory, IP address, shared ports, software that are installed automatically, among others.
Install vagrant-vbguest plugin
Vagrant supports use of plugins that extends your functions, here you find some available plugins.
For improve performance and usability the VirtualBox provides the VBox Guest Additions that basically is a set of software and drivers that should be installed on guest operational system, for we don’t install it manually on every guest operational system, we’ll install the plugin vagrant-vbguest and it will do automatically the installation.
vagrant plugin install vagrant-vbguest
Now that vagrant-vbguest went installed it will install and configure VBox Guest Additions always that a virtual machine will started though Vagrant.
Create Vagrantfile
Let’s create the Vagrantfile in directory that we wish shared with the VM, in this sample we’ll create a VM with Fedora 28 cloud base, but you can use the box that you wish, only be certain that the chosen box is supported by VirtualBox, otherwise it will not works with this tutorial.
vagrant init fedora/28-cloud-base
The Vagrantfile uses syntax of Ruby(but you don’t need know programming in Ruby), you can change the configurations as necessary, at this article we’ll use the default configuration, for we not to get away from the main goal.
Start VM
After create the Vagrantfile we going to request to Vagrant that start the VM, the command below works as follows: it look up by the Vagrantfile beginning from current directory until the root of your file system, after to find and to read the Vagrantfile it will check if the box defined in the file there is locally, case not exists, the download will made and only then the VM will started, with all configurations defined in the Vagrantfile.
All this process can be delay depending of your hardware and network, mainly when is necessary to download of the box.
vagrant up
Access VM
The access to VM is through SSH, making our lives easier the Vagrant provides the command below for we to connect with VM, then we don’t need to concern with users, IP address or passwords.
vagrant ssh
If everything are right, now you’re logged in VM and can do everything what do you’d in a common distribution, install programs, make downloads, create files and everything will be waiting for you on next time that you boot and access the VM.
By default the directory shared is mounted in VM at /vagrant, but you can change it in Vagrantfile, to access that, run.
cd /vagrant
Running ls
in directory /vagrant you should see the file Vagrantfile in the list of files present in this directory, every files created, deleted or updated in this directory will changed on your machine and in VM simultaneously, not mattering on which machine the operation has been made.
Shutdown VM
For shutdown a VM using Vagrant run the command below in directory where is the Vagrantfile or in your sub-directories.
vagrant halt
Delete VM
Case you need to delete some VM, so run.
vagrant destroy
Wrapping up
Opening the VirtualBox you can see all VMs created by Vagrant, as said previously the Vagrant isn’t a virtualizer, for avoid future troubles I recommend that you don’t change the VM configurations through VirtualBox GUI, instead always use the Vagrantfile.
Then we arrived to the end of this tutorial, now you should able to easily to create virtual machines with Vagrant.