Article Directory
This article was first published in: https://www.itcoder.tech/posts/how-to-install-vagrant-on-ubuntu-20-04/
Vagrant is a command line tool for building and managing virtual development environments.
By default, Vagrant prepares the environment on VirtualBox, Hyper-V, and Docker. Support other providers, for example, Libvirt (KVM), VMware and AWS can be enabled through the Vagrant plug-in system.
Vagrant is usually used by developers to build a development environment that matches the production environment.
This article describes how to install Vagrant on an Ubuntu 20.04 machine. We will use VirtualBox, the default provider of Vagrant.
We will provide virtual machines based on VirtualBox.
If VirtualBox is not installed on your system, you can install it by running the following command:
sudo apt update
sudo apt install virtualbox
The Vagrant package is provided in the Ubuntu source repository and is not frequently updated. We will download and install the latest version of Vagrant from the official Vagrant website.
At the time of writing this article, the latest version of Vagrant is 2.2.9. Browse Vagrant download page to see if the latest version of Vagrant is available.
Use wget to download the Vagrant package:
curl -O https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb
Once the download is complete, enter the following command to install it:
sudo apt install ./vagrant_2.2.9_x86_64.deb
To verify that the installation was successful, run the following command to print the Vagrant version:
vagrant --version
The output is similar to the following:
Vagrant 2.2.9
Creating a Vagrant project is very simple, define a Vagrantfile in the project root directory.
Run the following command to create a folder, and cd to switch to this directory:
mkdir ~/my-vagrant-project
cd ~/my-vagrant-project
Next, use vagrant init
plus the box you want to use to initialize a new Vagrantfile.
The box is the package format of the Vagrant environment. You can find the box list in Vagrant box page.
In this example, we use the centos/8
box:
vagrant init centos/8
Output:
A `Vagrantfile` has been placed inthis directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
` vagrantup.com`for more information on using Vagrant.
Vagrantfile is a Ruby file that describes how to configure and provide virtual machines. You can open Vagrantfile, read the notes, and make adjustments according to your own needs.
Run the vagrant up
command to create and configure the virtual machine according to the content specified in the Vagrantfile.
vagrant up
==> default: Configuring and enabling network interfaces...default: SSH address:192.168.121.74:22default: SSH username: vagrant
default: SSH auth method:private key
==> default: Rsyncing folder:/home/linuxize/Vagrant/my-vagrant-project/=>/vagrant
Vagrant mounts the project directory to the /vagrant
directory of the virtual machine. This allows you to manipulate your project files on your host.
To access your virtual machine using SSH, run:
vagrant ssh
You can stop the virtual machine with the following command:
vagrant halt
To release all resources in the process of creating a virtual machine, enter:
vagrant destroy
We showed you how to install Vagrant on Ubuntu 20.04 and create a basic Vagrant project.
To find more information about Vagrant, visit Vagrant official documentation page.
If you have any questions, please contact us in the following ways:
WeChat:
WeChat group: add the above WeChat, remark the WeChat group
QQ: 3217680847
QQ Group: 82695646
Recommended Posts