Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vagrant box add vs. vagrant init?

Tags:

vagrant

I'm reading the Vagrant docs on boxes and not understanding the difference between:

  • vagrant box add hashicorp/precise32; vs.
  • vagrant init hashicorp/precise32

The latter fetches the hashicorp/precise32 box from a remote catalog, and then creates a Vagrantfile for spinning up an instance of that box. But I don't see how that's different than the box add method.

So I ask: What's the difference between these two commands and when is it appropriate to use each of them?

like image 646
smeeb Avatar asked Aug 14 '15 16:08

smeeb


People also ask

What does vagrant box add do?

You can add a box to Vagrant with vagrant box add . This stores the box under a specific name so that multiple Vagrant environments can re-use it.

What is vagrant init?

Command: vagrant init [name [url]] This initializes the current directory to be a Vagrant environment by creating an initial Vagrantfile if one does not already exist. If a first argument is given, it will prepopulate the config.

Can I have more than one vagrant box?

Vagrant is able to define and control multiple guest machines per Vagrantfile. This is known as a "multi-machine" environment. These machines are generally able to work together or are somehow associated with each other.

What is the command to start a vagrant box?

1 - Vagrant Init In this example, I want to create a very basic Vagrantfile based on a box used from Vagrant Cloud. To do this I simply run vagrant init with the box address. `vagrantup.com` for more information on using Vagrant.


1 Answers

vagrant box add hashicorp/precise32 

just download the box image into your vagrant application while:

vagrant init hashicorp/precise32

make a vagrant file in current directory. if vagrant box image hasn`t been downloaded before. then it try to download the vagrant box image.

in the scenario which vagrant box has been added then we want to init a vagrant file. in shell we can get an name auto complete with Tab button, because it knows the vagrant image already.

like image 88
Abilogos Avatar answered Sep 19 '22 14:09

Abilogos