vagrant/website/content/docs/cli/init.mdx

71 lines
1.8 KiB
Text
Raw Normal View History

2020-05-05 18:11:12 -04:00
---
2020-05-06 17:36:09 -04:00
layout: docs
page_title: vagrant init - Command-Line Interface
2020-05-05 18:11:12 -04:00
description: |-
The "vagrant init" command is used to initialize the current directory to be
a Vagrant environment by creating an initial Vagrantfile.
---
# Init
**Command: `vagrant init [name [url]]`**
This initializes the current directory to be a Vagrant environment
2023-01-19 19:27:47 -05:00
by creating an initial [Vagrantfile](/vagrant/docs/vagrantfile/) if
2020-05-05 18:11:12 -04:00
one does not already exist.
If a first argument is given, it will prepopulate the `config.vm.box`
setting in the created Vagrantfile.
If a second argument is given, it will prepopulate the `config.vm.box_url`
setting in the created Vagrantfile.
## Options
- `--box-version` - (Optional) The box version or box version constraint to add
to the `Vagrantfile`.
- `--force` - If specified, this command will overwrite any existing
`Vagrantfile`.
- `--minimal` - If specified, a minimal Vagrantfile will be created. This
Vagrantfile does not contain the instructional comments that the normal
Vagrantfile contains.
- `--output FILE` - This will output the Vagrantfile to the given file.
If this is "-", the Vagrantfile will be sent to stdout.
- `--template FILE` - Provide a custom ERB template for generating the Vagrantfile.
## Examples
Create a base Vagrantfile:
2020-05-07 19:19:35 -04:00
```shell-session
2020-05-05 18:11:12 -04:00
$ vagrant init hashicorp/bionic64
```
Create a minimal Vagrantfile (no comments or helpers):
2020-05-07 19:19:35 -04:00
```shell-session
2020-05-05 18:11:12 -04:00
$ vagrant init -m hashicorp/bionic64
```
Create a new Vagrantfile, overwriting the one at the current path:
2020-05-07 19:19:35 -04:00
```shell-session
2020-05-05 18:11:12 -04:00
$ vagrant init -f hashicorp/bionic64
```
Create a Vagrantfile with the specific box, from the specific box URL:
2020-05-07 19:19:35 -04:00
```shell-session
2020-05-21 16:56:28 -04:00
$ vagrant init my-company-box https://example.com/my-company.box
2020-05-05 18:11:12 -04:00
```
Create a Vagrantfile, locking the box to a version constraint:
2020-05-07 19:19:35 -04:00
```shell-session
2020-05-05 18:11:12 -04:00
$ vagrant init --box-version '> 0.1.5' hashicorp/bionic64
```