Create a root directory for your project.
$ mkdir vagrant_demo
Change to root directory
$ cd vagrant_demo
$ vagrant init
This will place a Vagrantfile in your current directory.
$ vagrant init ubuntu/trusty64
You can also run vagrant init in a pre-existing directory to set up Vagrant for an existing project.
Boxes are broken down into two parts - the username and the box name - separated by a slash. The username is "ubuntu", and the box is "precise64" in the above command.
Vagrant uses a base image to quickly clone a virtual machine. These base images are known as "boxes" in Vagrant.
If you have not added a box yet, you can do so now
$ vagrant box add ubuntu/trusty64
This will download the box named "ubuntu/trusty64" from Vagrant Cloud box catalog.
you can also add boxes from a local file, custom URL, etc.
The box has been added to Vagrant, we need to configure our project to use it as a base. Open the Vagrantfile and change the contents to the following:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
end
The "ubuntu/trusty64" in this case must match the name you used to add the box above. This is how Vagrant knows what box to use. If the box was not added before, Vagrant will automatically download and add the box when it is run.
You may also specify the URL to a box directly using config.vm.box_url:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.box_url = "https://vagrantcloud.com/ubuntu/trusty64"
end
To boot your first Vagrant environment.
$ vagrant up
SSH into the machine:
$ vagrant ssh
The SSH session can be terminated with CTRL+D.
$ vagrant@trusty64:~$ logout
Connection to 127.0.0.1 closed.