Basic Vagrant commands

vagrant init [name [url]]

Initializes the Vagrant environment and creates the Vagrantfile.

$ vagrant init centos/7


A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`` for more information on using Vagrant.

vagrant up [name|id]

Creates and configures the Virtual Machine from the Vagrantfile.

$ vagrant up 


==> default: Configuring and enabling network interfaces...
    default: SSH address:
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Rsyncing folder: /home/naavi/Vagrant/my-vagrant/ => /vagrant

vagrant status [name|id]

Displays running or stopped VMs.

$ vagrant status 


Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

vagrant halt [name|id]

Attempts a graceful shutdown.

$ vagrant halt 


==> default: Attempting graceful shutdown of VM...

vagrant destroy [name|id]

Removes the guest machine.

$ vagrant destroy


default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...

vagrant ssh [name|id]

SSH into the guest machine or logs into the guest machine.

$ vagrant ssh 


Welcome to Ubuntu 16.04.7 LTS (GNU/Linux 4.4.0-187-generic x86_64)

 * Documentation:
 * Management:
 * Support:

 * Kubernetes 1.19 is out! Get it in one command with:

     sudo snap install microk8s --channel=1.19 --classic has docs and details.

8 packages can be updated.
0 updates are security updates.

New release '18.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Last login: Tue Sep  1 05:42:38 2020 from

vagrant suspend [name|id]

Suspends the machine in its current state and does not shutdown.

$ vagrant suspend


==> default: Saving VM state and suspending execution...

vagrant resume [name|id]

Starts the guest machine from suspended or halt.

$ vagrant resume


==> default: Resuming suspended VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address:
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

vagrant box add ADDRESS

The vagrant box add ADDRESS command downloads the box from the cloud repository and stores it in your local environment. It does not initialize the Vagrantfile.

$ vagrant box add centos/7 

vagrant global-status

This command will show the current state of the Vagrant VM in your system, regardless of the directory.

$ vagrant global-status


id       name    provider   state    directory                           
5c7d007  default virtualbox poweroff /home/naavi/Downloads/vag           
14d0e56  default virtualbox poweroff /home/naavi/Downloads/vag2          
The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date (use "vagrant global-status --prune" to prune invalid
entries). To interact with any of the machines, you can go to that
directory and run Vagrant, or you can use the ID directly with
Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"

Get hands-on with 1200+ tech skills courses.