vagrant installation and usage

2023-03-18 hit count image

let's see how to install virtualbox, vagrant to create virtual machine in virtual environment and how to usage vagrant to create virtual machine.

outline

we want to create backend - server development environment same like server. so in here, we will introduce how to use vagrant to make virtual machine.

install virtualbox

vagrant is virtual machine management tool. in other words, vagrant is a tool to create and manage virtual machine on virtual environment. so to manage virtual environment is not vagrant feature. there are many tools to create and manage virtual environment but we will use virtualbox in here.

click below link to go to virtualbox download site.

when you see below screen, download and install virtualbox to your PC.

virtualbox donwload page

to download and install virtualbox is same to download and install normal software so we will skip to talk about downloading and installing.

after installation, you can see below screen since you execute virtualbox.

virtualbox installed

install vagrant

now we can make virtual environment by virtualbox. let’s see how to install vagrant which is helpful to create virtual machine on virtual environment.

click below link to go to vagrant download site.

after clicking above link to go to vagrant download site, you can see below screen.

vagrant download site

select your PC OS installer and download it. we also skip how to download and install vagrant because it’s same to download and install normal software.

after installing, execute below command to check vagrant is installed.

vagrant --version

if vagrant is installed, you can see vagrant version like below.

Vagrant 2.2.1

add box

add box that vagrant will use to make virtual machine. box is a package include OS of virtual machine and softwares in OS. below links are official basic box and vagrant user box site.

execute below vagrant command to add box to your pc.

  • add official box
vagrant box add centos/7
  • add user box
vagrant box add centos66  https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box

we will use official box that is bento/ubuntu-16.04.

execute below vagrant command to add bento/ubuntu-16.04 box to your PC.

vagrant box add bento/ubuntu-16.04

execute below vagrant command to check added box list.

vagrant box list

if you add wrong box, it’s possible to delete it by executing below vagrant command.

vagrant box remove bento/ubuntu-16.04

create virtual machine setting

execute below vagrant command to create virtual machine setting using vagrant and added box.

# mkdir create your project folder
mkdir temp
cd temp
vagrant init bento/ubuntu-16.04

you can see Vagrantfile in the folder you executed command(temp). below code is contents of Vagrantfilefile that we removed comment out(#).

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-16.04"
end

create virtual machine

execute below vagrant command to create virtual machine with Vagrantfile we made above.

vagrant up

execute virtualbox we downloaded and installed, we can see one virtual machine.

virtualbox with virtual machine

execute below vagrant command to access vitual machine.

vagrant ssh

execute below command to come back from virtual machine to local PC.

exit

stop virtual machine

if you want to stop virtual machine, execute below vagrant command.

vagrant halt

delete virtual machine

if virtual machine is not needed anymore, execute below vagrant command to delete it.

vagrant destroy

completed

we saw how to make virtual machine by vagrant. in next blog posts, we will introduce how to configure development environment by editing Vagrantfile file and how to set development environment in virtual machine.

Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!

App promotion

You can use the applications that are created by this blog writer Deku.
Deku created the applications with Flutter.

If you have interested, please try to download them for free.

Posts