10
votes

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?

2

2 Answers

7
votes

vagrant box add would just add the box and don't create a Vagrantfile. That's it.

I'm always using vagrant init boxname boxurl, but there might be use cases where you don't want to place a Vagrantfile. Let's say you want to add a couple of images in a loop for example.

1
votes
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.