Setting Up Ubuntu in a Virtual Machine

Running Linux in a virtual machine gives you the complete experience - a full graphical desktop, complete isolation from your main OS, and the ability to snapshot and restore your system.

This takes longer to set up than WSL2 or Docker, but you'll learn valuable VM skills used in enterprise environments.

Requirements

  • 8GB+ RAM (4GB minimum, will be slow)
  • 25GB free disk space
  • VirtualBox installed (free)
  • Ubuntu ISO downloaded

Step 1: Download VirtualBox

Go to virtualbox.org and download VirtualBox for your OS:

  • Windows: "Windows hosts"
  • Mac: "macOS hosts"
  • Linux: Use your package manager

Install with default options.

Step 2: Download Ubuntu

Go to ubuntu.com/download/desktop and download Ubuntu 24.04 LTS.

Why LTS?

LTS (Long Term Support) versions are stable and supported for 5 years. Perfect for learning - things won't randomly break.

The download is about 5GB. Save it somewhere you can find it.

Step 3: Create the Virtual Machine

  1. Open VirtualBox

  2. Click New

  3. Configure:

    • Name: Ubuntu (or whatever you want)
    • Folder: Leave default
    • ISO Image: Browse and select the Ubuntu ISO you downloaded
    • Check Skip Unattended Installation (we'll do it manually)
  4. Click Next

Step 4: Allocate Resources

Memory (RAM):

  • Minimum: 4096 MB (4GB)
  • Recommended: 8192 MB (8GB)
  • Don't exceed 50% of your total RAM

Processors:

  • Minimum: 2 CPUs
  • Recommended: 4 CPUs
  • Don't exceed 50% of your total cores

Click Next

Step 5: Create Virtual Hard Disk

  • Select Create a Virtual Hard Disk Now
  • Size: 25GB minimum (50GB if you have space)
  • Leave Pre-allocate Full Size unchecked (saves disk space)

Click Next then Finish

Step 6: Install Ubuntu

  1. Select your VM and click Start
  2. The VM boots from the Ubuntu ISO
  3. Select Try or Install Ubuntu
  4. Choose your language
  5. Select Install Ubuntu
  6. Choose Normal installation
  7. Check Download updates while installing Ubuntu
  8. Select Erase disk and install Ubuntu (this only affects the VM, not your real disk!)
  9. Create your user account:
    • Your name
    • Computer name
    • Username (lowercase)
    • Password (remember this!)
  10. Wait for installation (10-20 minutes)
  11. Click Restart Now

Remove the ISO

When it says "remove installation medium and press Enter" - just press Enter. VirtualBox handles this automatically.

Step 7: Post-Install Setup

After Ubuntu boots, log in and open the Terminal (Ctrl+Alt+T or search "Terminal"):

hljs bash
# Update your system
sudo apt update && sudo apt upgrade -y

# Install useful tools
sudo apt install git curl wget htop tree build-essential -y

Step 8: Install Guest Additions (Important!)

Guest Additions give you:

  • Better graphics performance
  • Shared clipboard (copy/paste between host and VM)
  • Shared folders
  • Better mouse integration

In your VM:

  1. Click Devices menu > Insert Guest Additions CD image
  2. Ubuntu will prompt to run the software - click Run
  3. Enter your password
  4. After it finishes, restart the VM

Now you can resize the VM window and Ubuntu will adjust automatically!

Step 9: Enable Shared Clipboard

  1. VM window menu: Devices > Shared Clipboard > Bidirectional

Now you can copy/paste between your host OS and Ubuntu.

Taking Snapshots

One huge advantage of VMs - you can save your state:

  1. Machine menu > Take Snapshot
  2. Name it something like "Fresh Install"

If you ever break something, you can restore to this point.

Opening the Terminal

In Ubuntu, you can open a terminal by:

  • Pressing Ctrl + Alt + T
  • Clicking the app grid and searching "Terminal"
  • Right-clicking the desktop > "Open in Terminal"

Troubleshooting

Common Mistakes

  • Not enough RAM: If Ubuntu is crawling, allocate more RAM in VM settings (power off first)
  • Skipping Guest Additions: Without it, you can't copy/paste or resize the window - install it!
  • Wrong Ubuntu version: Get the Desktop version, not Server. Server has no GUI
  • Nested virtualization: If running VirtualBox inside a VM (rare), you need special settings

VM won't start: "VT-x is disabled" Enable virtualization in your BIOS. Restart, enter BIOS (F2, F12, or Del), find Intel VT-x or AMD-V, enable it.

Screen stays black after boot Try increasing video memory: Settings > Display > Video Memory > 128MB

Guest Additions fails to install Install build dependencies first:

hljs bash
sudo apt install build-essential linux-headers-$(uname -r)

Then try inserting the Guest Additions CD again.

Shared clipboard doesn't work Make sure Guest Additions is installed AND you've enabled bidirectional clipboard in Devices menu.

Pro Tips

Don't full-screen unless you have a big monitor: Working in a window lets you reference this course side-by-side.

Take snapshots before experimenting: About to try something risky? Snapshot first.

Allocate more resources if it's slow: Power off the VM, go to Settings > System, and increase RAM/CPUs.

You're Ready!

You now have a complete Ubuntu Linux environment with a full desktop. This is identical to what you'd get installing Ubuntu on real hardware.

Head back to the course introduction and start learning - open that terminal with Ctrl+Alt+T!

Knowledge Check

What's the keyboard shortcut to open a terminal in Ubuntu?