Create Linux environment on Windows with Vagrant and Virtualbox
This article is to describe a way to quickly setup a Linux environment in a Windows operating system using Hashicorp Vagrant and Oracle Virtualbox.
Prerequisite: Hashicorp Vagrant and Oracle Virtualbox
Here are the steps to build the Linux environment
- Create a folder somewhere, for example linux-vm
- Inside this folder, create a file with no extension called Vagrantfile and copy the following content inside:
- In the linux-vm folder previously created, add a work directory, and a website directory so the content of the folder looks like:
- Launch Oracle Virtualbox
- Open Windows command prompt
- In the Command Prompt, navigate to the folder linux-vm previously created
- Execute the following command
Wait for the virtual machine to be deployed, it may take a minute
Now the Ubuntu virtual machine is running and there are:
- a synced folder named work: any change made in this folder will be available in the virtual machine as well
- a synced folder named website containing the file index.html. Any change in this folder will be available in the virtual machine
A running nginx web server available at the following address:
localhost:8080
#
# or 127.0.0.1:8080
The Ubuntu terminal is available with the following command — to be run in the linux-vm folder:
And that’s all.
Notes
- After the computer restart or for some reasons, the virtual machine may stop running. To launch it again select Start > Headless Start:
2. Note that by default, the full working folder — here the linux-vm folder — is synced with the virtual machine in the /vagrant folder:
OPTIONAL: Set an alias to connect easily to the Ubuntu virtual machine
- Create a folder called custom_scripts somewhere, for example in the C:\ directory
- In this folder, create a file called vm.bat with the following content:
Add the folder C:\custom_scripts to the PATH environment variable:
- Open Edit the system environment variables
- Click Environment variables
- Double click on Path in System variables block
- Click New and add the previously created folder path C:\custom_scripts
Now executing the command vm from anywhere will log in to the virtual machine:
I hope you like the article. If yes please clap and feel free to comment :)