How to Install Debian using Vagrant

How to Install Debian using Vagrant

Working on multiple OS on the same system makes it difficult to log on and log off your device and switch around between the operating systems. So the better option is to create a virtual machine on your system and can use a multiple OS over it.

Virtual Machine works on your current operating system by sharing the resources. To create a virtual machine, an open source software Oracle Virtual Box could be used. Given below are some easy steps on how to install Debian using Vagrant.

NOTE: The current OS here in this tutorial is Windows 8

Steps: How to install Debian using Vagrant

Step #1: Install Oracle Virtualbox

All the versions of Oracle Virtual Box could be downloaded from its official site. Here to install Debian using Vagrant, we will use Virtual Box 4.3 as it works better with Debian and is easy to share files between your current OS and the virtual machine.

Download a package of Virtual Box 4.3 that suits your current operating System as shown below:

Download-Virtualbox

Step #2: Install Vagrant

Visit the official site of Vagrant and under the downloads option, you will get a list of the Vagrant packages for different OS. Select the one that matches your current Operating System and install it.

Download-Vagrant

Step #3: Create a directory for Vagrant

Open up cmd or a terminal if you are using Linux and create a directory with the commands below. This will create a directory ‘Vagrant’ in your D: drive and under Vagrant there will be  a directory named vm2. So the structure would be D:/vagrant/vm2.

cd d:
mkdir vagrant
cd vagrant
mkdir vm2
cd vm2

Make-Directory

Step #4: Initialize the Vagrant in your directory

Once the directory is created give command vagrant init and this will initialize a .vagrant file in your directory. Once the vagrant is setup, a confirmation message would be displayed as in the below snapshot.

Vagrant-init

Step #5: Editing the .vagrant file

Now comes the critical part to edit the .vagrant file to install Debian over vagrant. Right click on the .vagrant file and open it with your favorite text editor and make the below given highlighted changes:

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
 # The most common configuration options are documented and commented below.
 # For a complete reference, please see the online documentation at
 # https://docs.vagrantup.com.

 # Every Vagrant development environment requires a box. You can search for
 # boxes at https://atlas.hashicorp.com/search.
 config.vm.box = "debian/contrib-jessie64"

 # Disable automatic box update checking. If you disable this, then
 # boxes will only be checked for updates when the user runs
 # `vagrant box outdated`. This is not recommended.
 config.vm.box_check_update = false

 # Create a forwarded port mapping which allows access to a specific port
 # within the machine from a port on the host machine. In the example below,
 # accessing "localhost:8080" will access port 80 on the guest machine.
 # config.vm.network "forwarded_port", guest: 80, host: 8080

 # Create a private network, which allows host-only access to the machine
 # using a specific IP.
 config.vm.network "private_network", ip: "192.168.33.10"

 # Create a public network, which generally matched to bridged network.
 # Bridged networks make the machine appear as another physical device on
 # your network.
 # config.vm.network "public_network"

 # Share an additional folder to the guest VM. The first argument is
 # the path on the host to the actual folder. The second argument is
 # the path on the guest to mount the folder. And the optional third
 # argument is a set of non-required options.
 config.vm.synced_folder "D:/vagrant/vm2", "/var/www/", type: 'nfs'

 # Provider-specific configuration so you can fine-tune various
 # backing providers for Vagrant. These expose provider-specific options.
 # Example for VirtualBox:
 #
 # config.vm.provider "virtualbox" do |vb|
 # # Display the VirtualBox GUI when booting the machine
 # vb.gui = true
 #
 # # Customize the amount of memory on the VM:
 # vb.memory = "1024"
 # end
 #
 # View the documentation for the provider you are using for more
 # information on available options.

 # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
 # such as FTP and Heroku are also available. See the documentation at
 # https://docs.vagrantup.com/v2/push/atlas.html for more information.
 # config.push.define "atlas" do |push|
 # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
 # end

 # Enable provisioning with a shell script. Additional provisioners such as
 # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
 # documentation for more information about their specific syntax and use.
 # config.vm.provision "shell", inline: <<-SHELL
 # apt-get update
 # apt-get install -y apache2
 # SHELL
end

The default .vagrant file avails multiple options to use in the vagrant. The edited line config.vm.box = “debian/contrib-jessie64” informs Vagrant to install debian/contrib-jessi64 box. Similarly, there are other publicly available boxes like ubuntu/trusty64ubuntu/trusty64centos/7 and much more.

The line config.vm.box_check_update = false instructs the Vagrant not to check for the latest updates of the box. config.vm.network “private_network”, ip: “192.168.33.10” sets up a private network for your system. The files stored on the virtual machine could be accessed by the ip mentioned here. In our case, it is 192.168.33.10.

The files on your current OS (here Windows 8) and the files on your virtual machine could be shared and the directories are mapped with the command  config.vm.synced_folder “D:/vagrant/vm2”, “/var/www/”, type: ‘nfs’  that was modified in the Vagrant file.

Step #6: Time to Install Debian

Installing an OS with the command line interface using the Vagrant is extremely simple as it does everything by itself. Once the file is modified give the below-given command vagrant up and this will start the installation of the OS Debian.

vagrant up

Vagrant-Up

Step #7:  Logging into Debian

After giving the command “vagrant up” the virtual machine is started and is running at the back end. Now its time to log into the actual Debian and start working.! Give the command:

vagrant ssh

The screen as below will show up.

Vagrant-SSH

Wola.! This completes our tutorial on how to install Debian using Vagrant..!

To get such more latest updates follow us on Facebook.

Related Post

About the Author

Rashika Raina

Rashika is working as Business Development Executive at Regur technology Solution. She has a zeal to learn & grow and passion for work in any competitive situation. Her interest lies in Sales, Marketing Strategies, International Marketing, Business development. Apart from this, she has a good hold in communication, presentation and Market research skills.