What is Vagrant, how to install it





Vagrant is a tool that can be used to create different development environments. This can be used to create a production environment which is exactly similar to the development environment. On the other hand, vagrant is a solution to the ‘IT WORKS IN MY MACHINE, WHY NOT YOURS’ problem. 

There was an era where you try to install and configure all prerequisites within your local machine for developing applications. At that time, a web application was merely a PHP script backed by a MySQL database. But now the complexity of the applications has increased and the tradition of developing applications has also changed. For example, modern web applications have a lot more moving parts accompanied by different technologies. At present, there are different dynamic languages like JavaScript, Python, Ruby while there are different database choices like MySQL, PostgreSQL, Redis, Riak, Cassandra etc. In addition to different languages and databases, there are multiple web servers, application servers and backend services as well. Apache, Nginx, Unicorn, Thin, RabbitMQ, Solr are some of them. So keeping up everything properly configured and installed locally in a machine is very challenging. 

Vagrant solves this problem by creating complete development environments sandboxed in a virtual machine. Ultimate objective is to lower the development environment setup time and make the development and production process efficient. Since vagrant creates a virtual environment within your machine, users can run different operating systems simultaneously. But this has its pros and cons as well. Let’s discuss its positive aspects first.

With vagrant, we can create a virtual machine for us based on any operating system we require. Moreover we can modify the physical properties of this virtual machine like the number of CPUs and RAM too. We can establish network interfaces to access that virtual machine from our own computer, from another device on the same network or from another virtual machine. We can set up shared folders so that we can edit files in our machine and also let those modifications to mirror over to other machines. Depending on different software that needs to install and configure, rising time of vagrant can vary. After that, everything is up to vagrant because vagrant handles the entire life cycle of the machine afterwards. 

By now, I assume that you understand that vagrant creates a development environment similar to the production environment. Is that all that vagrant can do? No, vagrant can do more. It can SSH into the machine. This would allow remote login and other remote network services to operate securely over an unsecured network. You can boot the machine as well as halt the machine at any time, moreover you can resume the machine too. Not only that, you can destroy the machine completely by deleting its virtual hard drive and metadata. 

A testing environment is required for testing various releases and new tools in your software development work. Vagrant supports that too. After all the greatest benefit is that you can package the machine state so that you can distribute it to the other developers when working as a team. So why not try vagrant? 


Installing Vagrant and VirtualBox

Here I will show you how to install Vagrant if you are running Linux OS. By default, Vagrant uses VirtualBox for managing virtualization. VirtualBox is a cross-platform virtualization application. It will display you the information and status of different virtual machines that runs in your machine. 




Installing Vagrant: 

$ sudo apt-get install vagrant
Otherwise you can download vagrant for your OS from here.



Installing Virtualbox:

$ sudo apt-get install virtualbox
Otherwise you can download the VirtualBox binaries for your OS from here.



If you want to make vagrant up, you should navigate to the directory that contains the Vagrantfile and execute the following command. This will copy a VM image to create a new virtual machine, apply configuration to it, boot it.

$ vagrant up
You may get an output similar to this through your VirtualBox interface.



If you want to shut down or power off the VM use the following command.

$ vagrant halt
If you want to shut down the virtual machine and delete its stored image, execute the following command. Note that this will delete all the files of that particular VM from your machine.

$ vagrant destroy




References

1) https://docs.vagrantup.com/v2/why-vagrant/
2) https://www.vagrantup.com/
3) https://www.virtualbox.org/wiki/Downloads


0 comments :

Post a Comment