As I told you in my last article 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 vagrants?
Open the terminal then go to the root user by typing:
1 |
sudo -s |
then you have to install VirtualBox by typing:
1 |
sudo apt-get install virtualbox virtualbox-dkms |
Installing Vagrant:
1 |
sudo apt-get install vagrant |
Now check the version of your vagrant application by typing:
1 |
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 the latest version, 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 the Debian package and now let’s install the updated package by typing:
1 2 |
sudo dpkg -i “package_name_what_you_have_downloaded.” |
Now check the version:
1 |
Vagrant -v |
The output should be 1.7.4
Now let’s get the vagrant box from its official site:
Now copy the URL of the box which you want to download then hit the command on the terminal:
1 |
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 machine from the root user, then you will not get the UI of your machine in VirtualBox.
Now let’s create a directory in which you will create your machine by typing:
1 |
mkdir -p “directory_name” |
Now we will enter in the directory ‘what you just made’ by typing:
1 |
cd “directry_name” |
Let’s initialize the vagrant by typing:
1 |
vagrant init |
Now check your directory by typing the “ls” command, you will see a file named Vagrantfile.
Just open it with your editor, I will open it with nano editor by typing:
1 2 |
nano Vagrantfile |
Now search the line named config.vm.box = “base” and change that base word with your box_name that you gave at the time of downloading the vagrant box.
Now in the next line, add your username & password by typing:
1 2 3 |
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 let’s give the IP address to your machine.
Find out the line “config.vm.network public_network”, firstly uncomment this line and then modify this line and it should be like this:
config.vm.network “public_network”, ip: “YOUR_IP_ADDRESS”
Now save this file and exit…!!!
Now let’s get your vagrant box up by typing:
1 |
vagrant up |
After getting it up, access your machine by typing:
1 |
vagrant ssh |
and now check your virtual box, you will get the GUI of your machine there. Similarly, you can create your machine in just a few steps how much you want….:)
Now if you want to destroy your vagrant box, hit the command:
1 |
vagrant destroy |
To halt your machine type:
1 2 |
vagrant halt |
Restart your machine type:
1 |
vagrant reload |
To check your currently running machines, type:
1 |
VBoxManage list runningvms |
Check the total number of vagrant machines that you have in your system type:
1 |
VBoxmanage list vms |
Now let’s talk about the backup of your machine box.
Yes, You can take a backup of your vagrant machine for the future, if your os gets corrupted, reinstalled, or upgraded, then your machine will not get corrupted and You will not lose your pre-installed application, for this, you just need to take a backup of your machine by typing:
Firstly shut down the machine.
To do that go to the directory in which you initialized your vagrant machine and then shut down thE machine by typing:
1 |
vagrant halt |
Now copy the name of your vagrant machine.
To know the name of your machine type:
1 |
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:
1 |
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 the next time you will run it, you will have to give the path of this box in your vagrant file and then your vagrant machine will be ready to use.