How to build VM on Windows 10 using VirtualBox, Vagrant, and Git Bash?
This post provides you with an easiest and concise way to set up, build, and run virtual machine on Windows with the power of VirtualBox, Vagrant, and Git Bash. Let's briefly discuss these tools: VirtualBox, Vagrant, and Git Bash. Then I take through the installation process and some topic discussion.
- Virtual Machine (VM): This is an environment that provides you to run a guest OS on your existing Host Machine. This becomes the basis for software development and enables developers to begin at a set starting point.
- Host Machine: This is an Intel or AMD based machines where you are to create VM. No matter what operating system resides on your Host Machine because VirtualBox supports Windows, Mac OS X, Linux, and Oracle Solaris operating systems.
How to install VirtualBox in Windows 10?
VirtualBox is a hypervisor. You can't build a VM without the hypervisor, so you need to install VirtualBox. In our case, we have a host machine that runs Windows OS. This is a place where you build a VM and run guest OS (Linux Ubuntu 18.04 LTS) with the help of VirtualBox. Start the installation with VirtualBox set up process. Here are the steps to be followed.
- Download the latest VirtualBox installer.
- Open the installer, proceed with Next and Finish prompts to set up VirtualBox.
- After successful installation, you can find the VirtualBox icon in the dashboard or from the Windows starter menu.
In case, if you are using hypervisor such as Hyper-V, you need to disable it. There are two ways to disable Hyper-V, please follow the below steps.
# Disable Hyper-V from UI. Control Panel Programs Programs and Feature Turn Windows Features on or off Hyper-V: false # Disable Hyper-V from PowerShell. $ Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
Suppose, you face failure on VM creation, disable Secure Boot on BIOS. BIOS setup menu depends upon the machine model. So check and disable Secure Boot according to your machine configuration.
How to install and configure Git Bash in Windows 10?
Git Bash is one of the tools available in Git for Windows application. It is a Bash emulation that helps you to run Git commands on CLI. It is the same as Git commands executing on Linux or Unix operating system. It also provides common Bash shell commands such as SSH, CAT, FIND, etc. Git Bash can provide a robust shell experience on Windows. Now let's see Git Bash installation.
- Download the latest Git for Windows installer.
- Open the installer, proceed with Next and Finish prompts to set up Git.
- After successful installation, you can find Git Bash on the Windows starter menu.
- Open Git Bash and configure your username and email address.
# Set your name globally in Git. $ git config --global user.name "<YOUR_NAME>" # Set your email globally in Git. $ git config --global user.email "<YOUR_EMAIL>"
How to install Vagrant in Windows 10?
Vagrant is a powerful open source product developed by HashiCorp that helps you to automate building and maintaining virtual machines using hypervisors such as VirtualBox, VMware, Hyper-V, etc. Now let's see Vagrant installation.
- Download the latest Vagrant installer.
- Open the installer, proceed with Next and Finish prompts to set up Vagrant.
- After successful installation, you can find Vagrant icon the dashboard or from the Windows starter menu. You can also verify it on Git Bash. For that just open Git Bash and run the below command.
# Check Vagrant version. $ vagrant --version
If the installation is successful you will see the Vagrant version. After all the installation process completes, the next step is to build and maintain VM.
How to build Linux Ubuntu 18.04 virtual machine in Windows 10?
Here are the steps to build Linux Ubuntu 18.04 LTS virtual machine with the help of VirtualBox, Vagrant, and Git Bash. Building and maintaining VM with Vagrant is very simple. I am to discuss the robust way of using Vagrant.
- Go to your project directory and initialize Vagrant to create a Vagrantfile.
- The purpose of Vagrantfile is to define the VM specification i.e. what operating system you want, how much RAM you allocate, how many CPU cores you want to provide, what software packages you want to install automatically, etc.
Let's create Vagrantfile and write some important specifications.
# Initialize Vagrant VM. $ vagrant init ubuntu/bionic64 # Modify Vagrant VM configuration. $ vim Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "ubuntu/bionic64" config.vm.hostname = "sloopstash-workstation" config.vm.box_check_update = false config.vm.network "private_network", ip: "192.168.99.100" config.vm.synced_folder ".", "/vagrant", disabled: true config.ssh.username = "vagrant" config.ssh.private_key_path=["~/.vagrant.d/insecure_private_key"] config.ssh.insert_key = false config.vm.provider "virtualbox" do |vb| vb.gui = false vb.memory = "1024" vb.cpus = "2" vb.name = "sloopstash-workstation" end config.vm.provision "shell", inline: <<-SHELL apt-get update SHELL end
Once you defined your VM specifications, you can start the VM just by running the below command.
# Boot VM using Vagrant. $ vagrant up
I hope your VM is running properly on your host machine. Managing the running VM with commands is very simple. Here I've provided some managing commands which help you.
# SSH to the VM using Vagrant. $ vagrant ssh # Stop the VM using Vagrant. $ vagrant halt # Delete the VM using Vagrant. $ vagrant destroy
So far, you did set up the VirtualBox, Vagrant, and Git Bash. Now you can build and run the Linux Ubuntu 18.04 LTS virtual machine with the help of VirtualBox, Vagrant, and Git Bash in your host machine with all requirements.
I hope this post helps you. Thank you.