|
| 1 | +# Install Vagrant |
| 2 | +Vagrant is a tool for building and managing virtual machine environments in a single workflow which lowers development environment setup time and increases production parity. |
| 3 | + |
| 4 | +## Notice |
| 5 | +The Package Manager method's explanation is based on Ubuntu distribution of GNU/Linux. For more distributions explanations, please visit [Vagrant's Official Website](https://www.vagrantup.com). |
| 6 | + |
| 7 | +## Installation Guide |
| 8 | +You can either download the latest version from [Vagrant](https://www.vagrantup.com/downloads) website and install it, or use your package manager instead. |
| 9 | +Here's an explanation of both methods: |
| 10 | +* #### Using Zip File |
| 11 | +* #### Using Package Manager |
| 12 | + |
| 13 | +### Using Zip File |
| 14 | +First, download the Vagrant's latest zip file on your host using: |
| 15 | +``` |
| 16 | +wget https://releases.hashicorp.com/vagrant/2.2.16/vagrant_2.2.16_linux_amd64.zip |
| 17 | +``` |
| 18 | +After the file has been downloaded, you need to unzip the file using the command below: |
| 19 | +``` |
| 20 | +unzip vagrant_2.2.14_linux_amd64.zip |
| 21 | +``` |
| 22 | +In order to use the command globally, copy the extracted contents to binary directory: |
| 23 | +``` |
| 24 | +sudo cp vagrant /usr/local/bin/ |
| 25 | +``` |
| 26 | +You can confirm the installation by checking the version: |
| 27 | +``` |
| 28 | +vagrant version |
| 29 | +``` |
| 30 | +### Using Package Manager |
| 31 | +In this method, as the [Vagrant's Official](https://www.vagrantup.com/downloads) download page mentions, you need to run these commands in order: |
| 32 | +``` |
| 33 | +curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - |
| 34 | +
|
| 35 | +sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" |
| 36 | +
|
| 37 | +sudo apt-get update && sudo apt-get install vagrant |
| 38 | +``` |
| 39 | +And check the installed version using: |
| 40 | +``` |
| 41 | +vagrant version |
| 42 | +``` |
| 43 | +## Start With Vagrant |
| 44 | + |
| 45 | +### Making A Directory |
| 46 | +It's better to create a directory to store your VM's Vagrantfile: |
| 47 | +``` |
| 48 | +mkdir vagrant && cd vagrant |
| 49 | +``` |
| 50 | + |
| 51 | +### Initialize Vagrant |
| 52 | +To initialize your first VM, use: |
| 53 | +``` |
| 54 | +vagrant init |
| 55 | +``` |
| 56 | +This command, will create a Vagrantfile which configures your VM. You can change it with your own customizations. |
| 57 | + |
| 58 | +### Boxs |
| 59 | +Vagrant boxes help you create your VM based on different platforms. They include a readily-available Vagrantfile which can be altered. Boxes can be downloaded |
| 60 | +from the [Official Vagrant's](https://app.vagrantup.com) Boxes page. |
| 61 | +Use this command to initialize your VM with Ubuntu 20.04: |
| 62 | +``` |
| 63 | +vagrant init ubuntu/focal64 |
| 64 | +``` |
| 65 | +Another option would be configuring Vagranfile: |
| 66 | +``` |
| 67 | +Vagrant.configure("2") do |config| |
| 68 | + config.vm.box = "ubuntu/focal64" |
| 69 | +end |
| 70 | +``` |
| 71 | +Use this command to see all your Vagrant boxes: |
| 72 | +``` |
| 73 | +vagrant boxes list |
| 74 | +``` |
| 75 | + |
| 76 | +### Basic Commands |
| 77 | +* To run your VM: |
| 78 | +``` |
| 79 | +vagrant up |
| 80 | +``` |
| 81 | + |
| 82 | +* To shut down your VM: |
| 83 | +``` |
| 84 | +vagrant halt |
| 85 | +``` |
| 86 | + |
| 87 | +* To suspend your VM: |
| 88 | +``` |
| 89 | +vagrant suspend |
| 90 | +``` |
| 91 | + |
| 92 | +* To validate the Vagrantfile: |
| 93 | +``` |
| 94 | +vagrant validate |
| 95 | +``` |
| 96 | + |
| 97 | +* To provision your VM: |
| 98 | +``` |
| 99 | +vagrant provision |
| 100 | +``` |
| 101 | + |
| 102 | +* To run your VM without provisioning: |
| 103 | +``` |
| 104 | +vagrant up --no-provision |
| 105 | +``` |
| 106 | + |
| 107 | +* To SSH into your VM: |
| 108 | +``` |
| 109 | +vagrant ssh |
| 110 | +``` |
| 111 | +If you are using VirtualBox's GUI, the default user and password of your VM would be **'vagrant'** and **'vagrant'**. |
| 112 | + |
| 113 | +* To destroy your VM and associated files and drives: |
| 114 | +``` |
| 115 | +vagrant destroy |
| 116 | +``` |
| 117 | + |
| 118 | +* To destroy it with force: |
| 119 | +``` |
| 120 | +vagrant destroy -f |
| 121 | +``` |
| 122 | +* To check your VM status |
| 123 | +``` |
| 124 | +vagrant status |
| 125 | +``` |
| 126 | + |
| 127 | +* To check all your VMs' status |
| 128 | +``` |
| 129 | +vagrant global-status |
| 130 | +``` |
| 131 | + |
| 132 | +* To reload your VM: |
| 133 | +``` |
| 134 | +vagrant reload |
| 135 | +``` |
| 136 | + |
| 137 | +# References |
| 138 | +* [Vagrant Docs](https://www.vagrantup.com/docs) |
0 commit comments