How to Install Ubuntu on VirtualBox: The Ultimate Guide

Are you curious about Linux but hesitant to replace your main operating system? Or perhaps you want a safe environment to test new software without risking your daily driver PC. Installing Linux in a virtual machine is the perfect solution! In this in-depth guide, I‘ll walk you through the process of installing the popular Ubuntu distribution on VirtualBox, the powerful free and open-source virtualization platform.

What is Virtualization?

Virtualization allows you to run multiple operating systems simultaneously on a single physical computer. Each virtual machine (VM) acts as a completely separate computer with its own virtual hardware, isolated from the host operating system and other VMs.

The benefits of virtualization include:

  • Trying out different operating systems without modifying your main computer
  • Safely testing software in a sandboxed environment
  • Running old software that isn‘t compatible with your current OS
  • Consolidating physical servers into VMs for improved efficiency
  • Easily creating, backing up, and moving virtual machines between computers

Why VirtualBox?

VirtualBox is a popular open-source hypervisor (virtualization software) for x86 and AMD64/Intel64 architectures. Developed by Oracle, it runs on Windows, macOS, Linux and Solaris. Compared to competitors like VMware Workstation and Parallels Desktop, its key advantages are:

  • Completely free for personal and commercial use
  • Cross-platform with a large user community
  • Supports a wide range of guest operating systems
  • Integrates with the host OS via Guest Additions for seamless usability
  • Provides command-line tools for automation
  • Well-documented with an extensive manual and public API

Whether you‘re an individual home user or managing an enterprise data center, VirtualBox is a powerful tool to add to your arsenal.

Why Ubuntu?

We‘ve chosen Ubuntu as our Linux distribution for this guide due to its many strengths:

  • Consistently ranked as one of the most popular Linux distributions
  • Strong community support and extensive documentation
  • Frequent stable releases and long-term support (LTS) versions
  • Beginner-friendly while still powerful enough for advanced users
  • Compatible with a wide range of open-source and proprietary software
  • Customizable with thousands of free themes and extensions
  • Minimal system requirements can run smoothly even on older hardware

Of course, you can follow these same general steps to install other distributions in VirtualBox, such as Fedora, Linux Mint, or Arch Linux. Once you‘re comfortable with Ubuntu, I encourage you to explore the wide world of Linux!

Step 1: Install VirtualBox

First, download the appropriate VirtualBox package for your operating system from the official website:

https://www.virtualbox.org/wiki/Downloads

On Windows, run the downloaded executable and follow the prompts in the installation wizard. The defaults are generally fine, but be sure to keep the "VirtualBox Networking" feature checked if you want your VM to have internet access.

On macOS, open the downloaded DMG file and drag the VirtualBox icon into your Applications folder. You may need to allow the installation in System Preferences > Security & Privacy as VirtualBox isn‘t signed with an Apple developer certificate.

On Linux, you can either install VirtualBox from your distribution‘s package manager or use the official Oracle repositories for the latest version. For example, on Ubuntu:


sudo apt update
sudo apt install virtualbox virtualbox-ext-pack

Once installation is complete, launch VirtualBox to verify it‘s working properly. You should see the main VirtualBox Manager window.

Step 2: Create a New Virtual Machine

In the VirtualBox Manager window, click the "New" button to open the VM creation wizard.

In the "Name and operating system" screen:

  • Enter a descriptive name like "Ubuntu 20.04 VM"
  • Select "Linux" as the type and "Ubuntu (64-bit)" as the version
  • Choose a location to store the VM files or leave the default

Click "Next" to proceed to the "Memory size" screen:

  • Allocate at least 2048 MB (2 GB) for best performance
  • Don‘t exceed 50% of your computer‘s total RAM to avoid impacting the host OS

Click "Next" to proceed to the "Hard disk" screen:

  • Select "Create a virtual hard disk now" (default)
  • Choose "VDI (VirtualBox Disk Image)" as the file type
  • Choose "Dynamically allocated" for storage (recommended)
  • Specify at least 20 GB for the disk size to allow room for installing software

Click "Create" to finish the VM creation wizard. Your new Ubuntu VM will now appear in the VirtualBox Manager list.

Step 3: Install Ubuntu

Next, we need to download the Ubuntu installation ISO file and connect it to the VM‘s virtual optical drive:

Download the latest Ubuntu desktop release (e.g. 20.04) from the official website:

https://ubuntu.com/download/desktop

In VirtualBox Manager, select your Ubuntu VM and click "Settings". Go to the "Storage" section, select the empty optical drive, and click the CD icon to "Choose a disk file". Browse to the downloaded Ubuntu ISO file.

Back in VirtualBox Manager, select the Ubuntu VM and click "Start" to power it on. The VM will boot from the Ubuntu installation media.

When the Ubuntu installer appears, select your language and keyboard layout, then click "Install Ubuntu".

On the "Updates and other software" screen, choose "Normal installation" and select both "Download updates" and "Install third-party software" for the best experience. Click "Continue".

On the "Installation type" screen, choose "Erase disk and install Ubuntu". Don‘t worry, this only affects the VM‘s virtual disk, not your physical computer. Click "Install Now" then "Continue" to confirm.

Select your time zone on the map, then click "Continue".

Enter your name, computer name, username, and password, then click "Continue". Ubuntu will now finish installation and prompt you to restart.

On reboot, the VM will load into the full Ubuntu desktop environment, ready for use!

Step 4: Install Guest Additions (Optional)

VirtualBox Guest Additions provide extra features for better host-guest integration, such as:

  • Automatic window resizing
  • Shared folders and clipboard between host and guest
  • Improved video performance and optional 2D/3D acceleration
  • Seamless mode to blend guest and host desktops
  • Generic host-based input drivers for additional devices

To install Guest Additions in Ubuntu, boot up the VM and select "Devices" > "Insert Guest Additions CD Image" from the VirtualBox menu.

Open a terminal window and run:


sudo apt update 
sudo apt install build-essential dkms linux-headers-$(uname -r)
sudo /media/*/VBox*/VBoxLinuxAdditions.run

Reboot the VM to load the updated drivers. You should now be able to adjust the VM‘s window size, enable full-screen mode, and share files & folders. See the VirtualBox manual for details on configuring each feature.

Common Issues & Troubleshooting

While VirtualBox generally works well out-of-the-box, you may occasionally encounter issues like:

  • VM fails to boot or gets stuck on a black screen
    • Cause: Improperly configured BIOS, incorrect boot order, corrupt installation media
    • Fix: Check the VM settings, verify installation media integrity, enable EFI
  • Guest OS runs slowly or lags, especially with graphical applications
    • Cause: Insufficient CPU/RAM allocation, no Guest Additions, 3D acceleration not enabled
    • Fix: Allocate more resources in VM settings, install Guest Additions, enable 3D acceleration
  • No internet connection in the Ubuntu guest
    • Cause: VM network adapter set to NAT without port forwarding, incorrect network configuration in Ubuntu
    • Fix: Use Bridged mode instead of NAT, check Ubuntu network settings match host
  • USB devices not available in the Ubuntu guest
    • Cause: USB controller not enabled for VM, device not attached to VM, user permissions issue
    • Fix: Enable USB controller in VM settings, attach device via Devices menu, add user to vboxusers group
  • Shared folders not accessible in the Ubuntu guest
    • Cause: Guest Additions not installed, shared folders not configured, incorrect permissions
    • Fix: Install Guest Additions package, configure shared folders in VM settings, mount with correct permissions

When troubleshooting, consult the detailed VirtualBox manual and logs. Try different VM settings systematically. Search online forums and communities for others who have solved similar problems. If all else fails, reinstalling Ubuntu from scratch only takes a few minutes in a VM.

Conclusion

Virtual machines are a powerful tool for developers, system administrators, and curious tinkerers alike. With this guide, you should now have a functional Ubuntu VM running in VirtualBox, ready to explore. Some next steps to consider:

  • Install additional software & development tools in the VM
  • Experiment with different networking modes to integrate with the host
  • Take VM snapshots before making major changes to preserve states
  • Clone the Ubuntu VM to rapidly spin up multiple test environments
  • Try other Linux distributions or operating systems like Windows or BSD

I hope this guide has been helpful in your Linux journey! The skills you learn with VirtualBox and Ubuntu will serve you well across many domains. Don‘t be afraid to dive deep, break things, and learn from mistakes – that‘s the beauty of disposable VMs. Keep an open mind and have fun!

Additional Resources

Similar Posts