Installing Linux Using a Virtual Machine
If we want to experiment with Linux without affecting our main operating system (OS) at all, we can use a virtual machine (VM). We can run Linux directly atop our primary OS, whether it’s macOS or Windows.
In this tutorial, we will specifically talk about installing a Linux distribution called Ubuntu inside our VM software. The steps include:
Step 1: Installing VirtualBox
Step 2: Creating a VM in VirtualBox
Step 3: Installing Linux on VM
Let’s go through the steps in detail.
Step 1: Installing VirtualBox
VirtualBox is an open-source hypervisor developed by Oracle. It is similar to an emulator that creates and runs VMs where we can install different OSs without having to tinker with our disk partitions or worry about impacting our primary OS. Instead, we run a different OS like Ubuntu as if it were another program running on our computer.
To install VirtualBox, first go to the download page on the VirtualBox website. Then, select and download the correct package for your primary OS (the host OS, in virtualization terminology).
Once the package is installed, install VirtualBox as you would typically install a program. Feel free to use the default installation options.
Now, let’s go to the next step.
Step 2: Creating a VM in VirtualBox
Once VirtualBox is installed on your machine, start the program, and you should see the VirtualBox Manager window open. In this screen, you will see options to create and add VMs to VirtualBox, as well as any VMs you have previously created.
To create and add a virtual machine in VirtualBox, follow these steps:
Step 1: Select the “New” button to create a new VM. The prompt will ask for a name for the VM and a file path for where to save the VM files. There are options for the “type” of OS you would like to install on your VM, such as Windows, macOS, or Linux. It will also ask for the “version” of the OS you will install, such as Ubuntu or Debian.
For this tutorial, please select Linux for the “Type”, Ubuntu (64-bit) for the “Version”, and select “Next”.
Step 2: This screen will ask you to select the memory size to allocate for your machine. This will set aside a certain amount of RAM on your host machine to be used for your VM when it runs.
Please allocate 1024 MB and select “Next”.
Step 3: Next, create a virtual hard disk for your VM, where you will save files and programs while operating your VM. Please select “Create a virtual hard disk now” and then click the “Create” button.
Step 4: You will be prompted to select the type of hard disk file. Select “VDI (VirtualBox Disk Image)” and click on “Next”.
Step 5: Select whether the new virtual disk should be of a “fixed size” or dynamically allocate space as it fills up. Select “Dynamically allocated” and click “Next”.
Step 6: Set the maximum size for the disk to store file data, and then click “Create” to finish creating the VM.
With the virtual machine created, let’s move on to installing Linux (Ubuntu) on it.
Step 3: Installing Linux on VM
In order to install an OS to a VM, you will need to install the OS just like you would on a regular computer. You’ll need to download a copy of the installation.
The latest LTS (Long-Term Support) version of Ubuntu can be downloaded from the official website.
Now, you should have everything ready to install Ubuntu on the virtual machine. To do it, follow these steps:
Step 1: From the VirtualBox Manager screen, double click the VM you created on the left and a prompt will appear asking to select the start-up disk. Use the dropdown menu to select the Ubuntu image that you downloaded in the previous step and click “Start” to boot the VM.
VirtualBox will open a new window where you can see the display for your VM. From this point on, all these instructions take place in the VirtualBox window loading Ubuntu.
Step 2: The VM will boot to a welcome screen where you can select “Install Ubuntu” to start the installation process. Follow the prompt to select your keyboard language. A normal installation will include a number of apps and software, whereas a minimal installation will only include basic utilities, and you can install your own as you go. We’ll use the normal installation for this tutorial. You can check “Download updates” to update software packages as part of the installation process.
Step 3: In the next screen, select “Erase disk and install Ubuntu”. This takes place inside your VM and won’t affect your primary disk. Click “Install now” to continue. Ubuntu will prompt you to select your location and create a username and password. Afterwards, the installation will begin.
The installation can take a bit of time, depending on your installation type and your internet speed:
When the installation finishes, restart the VM in order to use it:
After restarting the VM, you can log in to your account and use your Ubuntu machine. Since our Ubuntu installation is completely contained within a VM, it’s practically impossible to screw up your host computer.
Now that we’re done learning how to install Linux on VM, let’s explore the advantages of doing so.
Why install Linux on VM?
Installing Linux on VM offers several advantages:
- Risk-free exploration: Try Linux without modifying your existing system.
- Safe testing environment: Experiment with commands, scripts, and apps without worrying about crashes or malware.
- Cross-platform development: Develop Linux-based software even on Windows or macOS.
- Learning tool: Ideal for students and professionals studying Linux system administration, networking, and cybersecurity.
Conclusion
In this guide, we discussed the step-by-step process of installing Linux on a virtual machine using VirtualBox and also went through the advantages of performing this operation.
Installing Linux on VM is a smart way to explore the OS without commitment. Whether you’re a beginner or a seasoned developer, using a VM gives you a safe and flexible environment to learn, test, and grow your Linux skills. With tools like VirtualBox and readily available Linux distributions, you can get started in just minutes.
If you want to learn more about installing Linux on a virtual machine, check out the Introduction to Linux course on Codecademy.
Frequently asked questions
1. How to install Linux on a virtual machine?
- Download the appropriate Linux ISO file
- Create a virtual machine in VirtualBox
- Launch the virtual machine
- When prompted, select the Linux ISO file you downloaded
- Boot into the installer
- Follow the installation steps (choose language, keyboard, installation type, username, password)
- Wait until installation finishes and restart the VM to complete installing Linux on the VM
2. Do I need a powerful PC to run Linux on a VM?
Not necessarily. A modern computer with at least 8 GB RAM and a decent processor should handle most lightweight Linux distros on a VM comfortably.
3. Can I access the internet from my Linux VM?
Yes, Linux virtual machines can access the internet just like your main system.
4. Is it safe to install Linux on my main computer?
Yes, but beginners should install Linux on a virtual machine to avoid partitioning and data loss risks.
5. Can I use Linux software on my Windows PC through a VM?
Yes. That’s one of the main benefits. The VM lets you run Linux and its apps inside Windows (or macOS) without dual-booting.
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
- Article
Installing Linux Using a Virtual Machine
In this article, you will learn how to install Ubuntu, a Linux distribution, onto a virtual machine using VirtualBox. - Article
Programming Locally on a Chromebook
This article will teach you how to set up the Linux environment on your Chromebook so you can program and do Codecademy off-platform projects on your Chromebook. - Article
Linux OS
A Cybersecurity Analyst is expected to effectively analyze the operating systems of an organization. In this article, we'll discuss the Linux OS.
Learn more on Codecademy
- Dive into Linux, a useful and lightweight operating system with a large impact on open-source technology.
- Intermediate.1 hour
- In this introductory course, we'll be getting familiar with Linux and how to navigate within a Linux environment!
- With Certificate
- Intermediate.4 hours