This article is going to cover shortly how to add a Vagrant box from local or remote. The remote boxes are referred to the boxes needed to be installed via HTTP while the local boxes are boxes can be installed from the filesystem.
1. How to add a Vagrant box from local or remote
Let’s see the syntax of the below command:
1 |
vagrant box add [options] <name, url, or path> |
As for the location of the box, there are 3 options for us:
- name: the name of the box which will be downloaded from the publicly available catalog of Vagrant boxes
- url: the URL of the remote box.
- path: the path to the local box.
We will go through 3 options step by step in the next sections.
2.1. Add a remote box using name
This is the easiest way to install a box. For example, let’s assume that we want to install Ubuntu 16 box, we can to go the publicly available catalog , search for the box by name and find a box named ubuntu/xenial64. And to add that remote box to our environment, we just need to issue the command:
1 |
vagrant box add ubuntu/xenial64 |
Vagrant will download the box and install it automatically from the public catalog.
2.2. Add a remote box with URL
This way could be used when we want to add a box located at a specific URL and the box was not existed in the public catalog.
Let’s assume that we want to add a debian-jessie box from another website rather than the Vagrant public catalog.
1 |
vagrant box add https://atlas.hashicorp.com/ARTACK/boxes/debian-jessie |
2.3. Add a local box using path
This is a situation when we have a local box packaged by ourselves, or shared from our colleagues or even a box that was downloaded by ourselves. And below is the way how we can add a local box.
2.3.1. On Windows
The below example will add the ubuntu16.xenial64.box box at the D:\VagrantBoxes directory. Note that we also specify the name of the box is: ubuntu/xenial64
1 |
vagrant box add ubuntu/xenial64 file:///D:/VagrantBoxes/ubuntu16.xenial64.box |
An alternative way is to open the terminal, cd to the directory where the box is existing and install the box.
1 2 |
cd D:\VagrantBoxes vagrant box add ubuntu/xenial64 ubuntu16.xenial64.box |
2.3.2. On Linux
This example will add the ubuntu/xenial64 box at the /data/VagrantBoxes directory.
1 |
vagrant box add ubuntu/xenial64 /data/VagrantBoxes/ubuntu16.xenial64.box |
Note that we have just named the box: ubuntu/xenial64.
2. Summary
We have learned how to add a Vagrant box from local or remote. Note that for local boxes, we should specify the box name for the command because the installation may not find the metadata of the local boxes. In some cases, we also need to specify the hypervior provider with which the box should be used; otherwise, the default provider, VirtualBox will be used.
3. References
https://www.vagrantup.com/docs/getting-started/boxes.html