A step-by-step guide to setting up a Linux virtual machine using Vagrant and VirtualBox on Windows, and connecting it to VS Code.
- A Windows PC
- Git Bash installed
- Internet connection
Download and install Oracle VirtualBox from the official site:
Run the installer and follow the on-screen steps.
Download Vagrant from the official HashiCorp site:
Run the installer normally, then restart your computer before continuing.
Download the two configuration files from this repository:
Place both files (Vagrantfile and pg_config.sh) into a separate, dedicated folder on your machine.
- Open the folder containing the Vagrant files in Git Bash
- Run the following command:
vagrant upThis will take a while — the first run downloads the Linux box image. Be patient.
- When VirtualBox prompts you with any network/firewall dialogs, allow everything.
Once vagrant up finishes, connect to your Linux VM:
vagrant sshYour terminal prompt will change, confirming you are now inside the Linux VM.
To install the GCC compiler inside the VM:
sudo apt install gccTo exit the SSH session:
exitTo shut down the VM:
vagrant haltNote: Do not try to start or manage the VM directly from the VirtualBox GUI. Always use Vagrant commands from Git Bash.
Vagrant automatically creates a shared folder that is accessible both from your Windows machine and from inside the VM.
| Location | Path |
|---|---|
| Windows (your machine) | The folder where your Vagrantfile lives |
| Inside the VM | /vagrant |
cd /vagrant
lsAny file you see here is the same file in your Windows folder — edits are reflected instantly on both sides.
- Open VS Code
- Go to File → Open Folder
- Navigate to the folder containing your
Vagrantfile - Open it
Now whatever you create or edit in VS Code is immediately accessible inside the VM at /vagrant. This is the recommended workflow for editing code.
| Command | Description |
|---|---|
vagrant up |
Start (and provision) the VM |
vagrant ssh |
SSH into the running VM |
vagrant halt |
Shut down the VM |
vagrant reload |
Restart the VM |
vagrant destroy |
Delete the VM entirely |
cd /vagrant |
Access the shared folder (run inside VM) |
exit |
Exit the SSH session |
vagrant uphangs or times out — Make sure VirtualBox is installed and your BIOS has virtualization (VT-x/AMD-V) enabled.- Shared folder not mounting — Ensure VirtualBox Guest Additions are installed. Try
vagrant reload --provision. - SSH connection refused — Wait a moment and retry; the VM may still be booting.