We know that Vagrant is a tool for building complete development environments. It allows us to imitate the setup of a server on our local machine which can be easily reproduced on any system.
This article will show three useful routines for Vagrant: saving an existing Vagrant box setup, removing old/unused Vagrant box and restoring saved vagrant box. It is assumed that you are using Windows as host machine's OS and Cygwin command line interface. Throughout this article, we will be using centos7drupal name for our Vagrant box.
Saving an existing Vagrant box:
If your Vagrant box is still running, make sure to shut it down first:
Execute create Vagrant box package:
vagrant package --output centos7drupal.box
The Vagrant box package will be saved as centos7drupal.box file.
Removing an existing Vagrant box:
If your Vagrant box is still running, make sure it is shutdown:
Execute destroy Vagrant box:
Note: If you received this error message:
Vagrant is attempting to interface with the UI in a way that requires a TTY. Most actions in Vagrant that require a TTY have configuration switches to disable this requirement. Please do that or run Vagrant with TTY.
... execute this command instead:
vagrant destroy -f
Backup the existing Vagrant config file and delete it:
cp Vagrantfile Vagrantfile.bak rm Vagrantfile
Delete the actual Vagrant box image:
Restoring saved Vagrant box:
Execute add Vagrant box:
vagrant box add centos7drupal centos7drupal.box
Initialize your Vagrant box:
vagrant init centos7drupal
That command will create generic Vagrant config file. If you prefer to use the previous Vagrant config file, execute the following commands:
rm Vagrantfile mv Vagrantfile.bak Vagrantfile
Boot your Vagrant box:
Only the initial boot-up will take longer time than the succeeding boots.