How to Create a Virtual Machine using Vagrant

creating virtual machines using vagrant

For creating a virtual machine using vagrant, first, you have to know about two things. First is “what is a virtual machine ?” and the second is “what is vagrant ?”

Virtual Machine

The virtual machine itself tells that it is a kind of virtual program or a virtual application environment that helps you to run different operating systems in your current operating system. Another benefit is that each individual virtual machine itself acts as dedicated hardware.

Vagrant

Vagrant helps to configure easily and conveniently for development environments. It helps to easily separate or detach dependencies from other working tools. So there is no need for sacrificing one particular tool for the working of another tool. Because of this advantage, you will get a reliable situation to work with.

For creating a virtual machine using vagrant, you can use different tools. The most popular one is VirtualBox. So you have to install VirtualBox for your particular operating system.

Steps for creating Virtual Machine using Vagrant

1) Install the VirtualBox from the below link :

www.virtualbox.org/wiki/Downloads

2) Install Vagrant From the below link:

www.vagrantup.com/downloads.html

3) Create a directory and cd into the directory using the following command.

mkdir centos && cd centos

4) Now you have to add centos box to your system. It can found in VagrantCloud. You will get the centos file name from the below link.

https://atlas.hashicorp.com/boxes/search?utf8=%E2%9C%93&sort=&provider=&q=centos

5) Copy the first file from the above website link and paste that after typing the command: vagrant box add. Then the command will be:

vagrant box add puphpet/centos65-x64

8) Then the centos vagrant box will be added. You will see the output as shown below.

==> box: Loading metadata for box 'puphpet/centos65-x64'
box: URL: https://atlas.hashicorp.com/puphpet/centos65-x64
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) parallels
2) VirtualBox
3) vmware_desktop

Enter your choice:

9) Next enter your choice. That means using which provider you are going to proceed. Here you can choose 2, that means you are using VirtualBox instead of parallels and vmware_desktop.

Enter your choice: 2
==> box: Adding box 'puphpet/centos65-x64' (v20151130) for provider: virtualbox
The box you're attempting to add already exists. Remove it before
adding it again or add it with the `--force` flag.

Name: puphpet/centos65-x64
Provider: virtualbox
Version: 20151130

10) You can check your vagrant box list, whether your centos files are listed inside or not.
For that, type the following command:

vagrant box list

11) Create the Vagrantfile using the centos box name. The command for creating vagrant file is:

vagrant init puppet/centos65-x64

12) Now type the list command to check if Vagrantfile has been created.

ls

13) Open the centos Vagrantfile from where you saved vagrant folder in your system. Then include the below contents only in that file using any text editor. If you don’t have one, you can use the sublime editor. The sublime editor can be downloaded from the below link.

www.sublimetext.com

Below are the contents that are necessary for creating a virtual machine. These are written in the ruby language and should be saved in the sublime editor.

vagrant.configure(2) do |config|

config.vm.box = "puphpet/centos65-x64"

config.vm.network "private_network", ip: "192.168.33.10"

config.vm.provider "virtualbox" do |vb|

vb.memory = "1024"
end
end

14) Then type the command : vagrant up to start the working of a virtual machine using vagrant.

vagrant up

15) Then check the status of the vagrant by typing the command.

vagrant status

16) By following these steps, you already created the virtual machine using vagrant.

If you want to connect the running vagrant machine to the shell, use the following command.

vagrant ssh

Similar Posts

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments