Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5489

Vagrant Implementation….!!!

$
0
0

Hello all, I am back as i told you in my last article that I will provide a very simple way that you can follow to get your vagrant machine up and running, Today lets implement it:

Firstly the question is, how to install vagrant?

Open the terminal then go to root user by typing:

sudo -s

then you have to install virtualbox by typing:

sudo apt-get install virtualbox virtualbox-dkms

Installing Vagrant:

sudo apt-get install vagrant

Now check the version of your vagrant application by typing:

vagrant -v

the output should be “vagrant 1.7.4”

Note:- “If you get the lower version of vagrant then upgrade it to 1.7.4, otherwise your vagrant file will not work perfectly”

To get latest version of vagrant, you need to download its updated package on the mentioned site below:

https://www.vagrantup.com/downloads.html

I am using ubuntu 14.04. So i have downloaded debian package and now lets install the updated package by typing:

sudo dpkg -i “package_name_what_you_have_downloaded.”

Now check the version of your vagrant by typing:

Vagrant -v

Output should be 1.7.4

Now lets get the vagrant box from its official site:

http://www.vagrantbox.es/

Now copy the URL of the box which you want to download then hit command on terminal:

vagrant box add “box_name” “box_URL_what_you_copied_from_its_site”

After downloading this box, you will have to come back to your user.

Note:- If you will create your vagrant machine from the root user, then you will not get the UI of your vagrant machine in virtualbox.

Now lets create a directory in which you will create your vagrant machine by typing:

mkdir -p “directory_name”

Now we will enter in the directory ‘what you just made’ by typing:

cd “directry_name”

Now initialize the vagrant by typing:

vagrant init

Now check your directory by typing:

ls

You will see a file named Vagrantfile.

Just open it with your editor, i will open with nano editor by typing:

nano Vagrantfile

Now search the line named config.vm.box = “base” and change that base word with your box_name what you gave at the time of downloading the vagrant box.

Now in the next line, add your username & password by typing:

config.ssh.username=“vagrant”

config.ssh.password=“vagrant”

Note:- You can keep your username & password by your choice, i kept vagrant because its default… :)

Now Lets give the ip address to your vagrant machine.

Find out the line “config.vm.network public_network”, firstly uncomment this line and then modify this line and it should be like:

config.vm.network “public_network”, ip: “YOUR_IP_ADDRESS”

Now save this file and exit…!!!

Now lets get your vagrant box up by typing:

vagrant up

After getting it up, access your vagrant machine by typing:

vagrant ssh

and now check your virtual box, you will get the GUI of your vagrant machine there. Similarly, you can create your machine in just few steps how much you want….:)

Now if you want to destroy your vagrant box, hit the command:

vagrant destroy

To halt your vagrant machine type:

vagrant halt

To restart your vagrant machine type:

vagrant reload

To check your currently running vagrant machines, type:

VBoxManage list runningvms

To check the total number of vagrant machines that you have in your system type:

VBoxmanage list vms

Now lets talk about the backup of your vagrant machine box.

Yes, You can take a backup of your vagrant machine for future, if your os gets corrupted, reinstalled or upgraded, then your vagrant machine will not get corrupted and You will not loose your pre-installed application, for this you just need to take backup of your vagrant machine by typing:

Firstly shut down the vagrant machine.

To do that go to the directory in which you initialized your vagrant machine and then shut down the vagrant machine by typing:

vagrant halt

Now copy the name of your vagrant machine.

To know the name of your vagrant machine type:

VBoxManage list vms

It will show the name and UID of your all VM machine.

Now copy the name of your vagrant machine whose you want to take backup and then type:

vagrant package –base “vagrant_machine_name” –output “path_to_the_box_where_you_want_to_keep_it.box”

after this command, you will get your virtual machine’s backup box now you can keep it anywhere in your local, in your cloud and next time you will run it, you will have to give the path of this box in your vagrantfile and then your vagrant machine will be ready to use.

If you have any query regarding this, just reply here and i will give the solution of your problem….:)


Viewing all articles
Browse latest Browse all 5489

Trending Articles