• 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 Leave a Comment

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. How to install KVM on Ubuntu 16.04 LTS Desktop
  10. How to install Docker on Ubuntu

Filed Under: Linux Tagged With: ubuntu, vagrant

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Linux Commands

How to set motd in linux

6 df Command Examples To Check Mounted Filesystem On Linux

What is Linux/Unix Internal And External Command

learn very useful alias command with examples

sed command to display text between two strings or keywords

How to test rpm package before installation

sed : find the pattern (keyword) and delete the line from file

Explore 70+ Articles On Linux Commands

Always Useful Tips And Tricks

How To Get SSH Public Key Fingerprint Information

Show visitor ip address php code

Nagios HTTP WARNING: HTTP/1.1 403 Forbidden

rsync all files,hidden files,symlinks,hardlinks to remotes Linux Server

convert space into new line using sed command

How to convert rpm file into deb file

Unix / Linux : How to print duplicate lines from file

Explore 90+ Article On "Linux Tips And Tricks"

You Might Like These Articles!

Linux basic command

Linux Basic Commands For Every Beginner

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

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission but Schools and Colleges can do in their Private Network
Proudly Blogging From Bharat.

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