• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Install Vagrant on Ubuntu and create first VM

May 25, 2020 by Sharad Chhetri

Vagrant is a Open Source software used for creating Virtual Machines in automated way. The software is written in Ruby language. The Vagrant is very useful for increasing the development productivity. We have seen the journey of Vagrant from Virtual box to current cloud providers, truly it is awesome to experience the growth of such a wonderful tool.

Basically Vagrant has two important building blocks

  • Providers: Vagrant supports providers like VirtualBox, Hyper-V, VMWare,Docker and AWS. Even you can develop your own custom providers. Find the Vagrant Providers List here.
  • Provisioners: In provisioners, it supports Ansible, Chef, Puppet, Salt etc. You can find the Vagrant Provisioning List here

Install Vagrant On Ubuntu

Download Vagrant from https://www.vagrantup.com/downloads.html. Ubuntu is debian based OS hence download the deb package.

As per your Operating System arch download the deb package either 32 bit or 64 bit. Our Ubuntu system is 64 bit so we will download 64 bit Vagrant Deb package. (use arch command to know – is your Operating System 32 or 64 bit)

wget command will download the package.

sudo apt -y update
sudo apt -y install wget
wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb

And dpkg -i package-name will install the .deb package.

sudo dpkg -i vagrant_2.2.9_x86_64.deb

Once it is installed, you can see the find the absolute path of vagrant command. Here is the example, we have used the command which vagrant.

sharad@linuxworld:~$ which vagrant
/usr/bin/vagrant
sharad@linuxworld:~$ 

Create your first Virtual Machine with Vagrant

Now after installing vagrant, we all are eager to create our first Virtual Machine through vagrant.

VERY IMPORTANT: By Default Vagrant provider is Virtual Box.

Prerequisite

Here in this post, we will use the Virtual Box. So first you should have Virtual Box installed on your system.
Follow our post and install VirtualBox on Ubuntu.

You can also use any other Vagrant Providers for creating Virtual Machines apart of Virtual Box. We have to do some slight changes for using other Vagrant Providers

  • Step 1: Create a directory from where you will manage the vagrant boxes.
    mkdir vagrant_boxes
    
  • Step 2: Create a new directory inside vagrant_boxes directory. The new directory name should represent the Virtual Machine Name. For example, to create CentOS 8 Virtual Machine, we will create directory called CentOS-8.
    mkdir -p vagrant_boxes/CentOS-8
    
  • Step 3: Now change to directory CentOS-8 and do vagrant init for initializing the vagrant base directory.
    This will create a Vagrantfile inside in that directory.
    In case you only run vagrant init, it will create a barebone Vagrantfile.Then you have to update image name value at config.vm.box in Vagrantfile.

    cd vagrant_boxes/CentOS-8
    vagrant init centos/8
    

    Given below is the screenshot depicting Step 1,2 and 3.

    vagrant init
    vagrant init

  • Step 4: Now we will run the command to pull the image from ‘Vagrant Cloud‘ and make the Virtual Machine running in system at a same time.
    In this example,we will pull the CentOS 8 image. Run the below given command.

    vagrant up
    

    This will pull the CentOS 8 image from Vagrant Cloud and once it is downloaded in system, it will run the Virtual Machine.

    vagrant cloud flow
    vagrant cloud flow

    Screenshot: It depicts the output of command ‘vagrant up’.

    vagrant up
    Output: vagrant up

    Open the Virtual Box, you can find the CentOS 8 Virtual Machine is up and running.

    vagrant

  • Step 5: To access the Virtual Machine, your prompt should be in same directory from where vagrant was initialized. Run the below command from there.
    vagrant ssh
    

    Now you can start doing your work. In Linux Virtual Machine, you can do sudo su and do your work as a superuser.

    vagrant ssh

Manage Virtual Machine with Vagrant

  • vagrant init: initializes a new Vagrant environment by creating a Vagrantfile
  • vagrant up: starts and provisions the vagrant environment
  • vagrant halt: stops the vagrant machine
  • vagrant suspend: suspends the machine
  • vagrant destroy: stops and deletes all traces of the vagrant machine

To learn more on vagrant, we will strongly suggest to go through with vagrant --help. It has many parameters. You can also create your own Virtual Machine image and push in ‘Vagrant Cloud’ and this is how many people voluntarily contribute in this awesome project.

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. Create single node Virtual Machine with Vagrant
  2. Learn Vagrant provision with shell provisioner examples
  3. Create multiple virtual machine with one Vagrantfile
  4. How to create own Git Server with Gitolite and Gitweb in Ubuntu
  5. Create upstart event system for ghost blog on Ubuntu
  6. Create desktop launcher in Unity Desktop Ubuntu 16.04 LTS
  7. How to create Ubuntu docker base image
  8. Install VirtualBox Guest Additions and create videos
  9. Install XFCE Desktop in Ubuntu through command line
  10. How to install flash player plugin in Ubuntu

Filed Under: Linux Tagged With: ubuntu, vagrant

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

Install libjpegtran by using yum command in CentOS 6.x

df command not showing correct free space in linux

AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework

Recover Linux Grub Password in linux rescue mode CentOS/Red Hat

Do not show line haveing particular keyword by grep command

Could not find make anywhere!!! Please edit the config section to include the path to make. at ./install.pl line 2101

Allow only members of Wheel group to use su command on RHEL/CentOS

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy