Setting up a Minimal Ubuntu VM on Windows and Mac
Published: 2020-11-03 18:08:04

# How to install Ubuntu on a Virtual Machine

Author: Nabeel Ahmed

>  Please scroll down to the operating system you use. (Windows or Mac).

## Windows 👾

It is much easier to set up a CLI (Command-Line Interface) environment for Windows as Microsoft has already implemented a Ubuntu subsystem virtual machine that is built onto Windows. Follow the steps below to install the subsystem:

1. Open the following link: https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6.
2. Click on the `Get` button and it should redirect you to the Microsoft Store app on your machine.
3. Install and wait for it to finish.
4. Once finished, type `Ubuntu` into the *Start* search box, and the app should pop up- click on it.
5. Once a Terminal is opened it should automatically begin the installation processes.
6. If you are prompted with the following message: `The Windows Subsystem for Linux optional component is not enabled. Please enable it and try again`. Complete the following steps to fix this else move to step 7:
   1. Open *Powershell* as **Administrator** (right-click Powershell in *Start* and select `Run as administrator`).
   2. Paste the following command into it: `dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart`.
   3. After the previous command is done running, paste the following: `dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart`.
   4. Finally, paste the following: `wsl --set-default-version 2`.
      1. If you run into the error of `wsl is not recognized`, paste the following command instead: `Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform`
   5. Once complete close *Powershell* and the *Ubuntu Subsystem* App and reopen the *Ubuntu Subsystem* App.
7. You will now be asked to fill in some details such as a `UNIX username` (pick anything you will remember your first name all lowercase should be enough) and a `UNIX password` (pick something you will remember because you will be using it a lot).
8. You are done! 👏

## macOS 🍎

It is a little bit harder to install a Linux virtual machine on macOS as you have to create the *Virtual Environment* yourself. Follow the steps below to install the Virtual Machine:

1. Head over to the following URL and download  *VirtualBox*, a free hypervisor that allows you to create virtualized environments on your machine. Make sure to click `OS X hosts` to start the download: https://www.virtualbox.org/wiki/Downloads.
2. As *VirtualBox* is downloading, install the *Ubuntu Minimal* disk alongside it, which will give us the CLI (Command-Line Interface) version of *Ubuntu*. Link for the download. Scroll down until you see your computer's architecture (64bit or 32bit) and click the latest version of *Ubuntu* within the list. The latest version should be number 1: https://help.ubuntu.com/community/Installation/MinimalCD.
3. Once *VirtualBox* has finished downloading, open the *VirtualBox* `.dmg` file. Double click on the `.pkg` icon in the *VirtualBox* drive folder to open the installation wizard. Once you complete the installation steps, close the drive window, and eject the drive.
4. Open *System Preferences* on Mac. Can be located by the following steps: Apple Logo (Absolute top-left of the screen) > System Preferences.
5. Open `Security & Privacy` and switch the tab to `General`.
6. Unlock the Lock that is located on the bottom left of the window. You will be prompted to enter your password.
7. Click  `Allow` beside the blocked software warning (This is a security warning because *VirtualBox* enables virtualization onto your computer).
8. Finally, open the *VirtualBox* app. This can be located by simply typing `VirtualBox` into the Spotlight Search (which can be open by pressing `cmd + space`).
9. After opening *VirtualBox*, you should be prompted to a window that has an image of a **_Penguin with building tools_**.
10. Click the `New` button and complete the following steps:
    1. On the window presented to you, type `CS Ubuntu Machine` into the name field- or whatever you'd like as long as you can remember the particular *virtual machine*.
    2. For the `Machine Folder`, it should default to `/Users/[your_username]/VirtualBox VMs`, which is fine. If it doesn't default to that, make a folder called `VirtualBox VMs` in the `Home` directory and select that in *VirtualBox*.
    3. For the `Type` field select: `Linux`.
    4. For the `Version` field select: `Ubuntu (64-bit) ` or `Ubuntu (32-bit) ` depending on your computer's architecture (64bit or 32bit). Once done, click `Continue`.
    5. For `Memory Size` drag the slider until it says `2048 MB` or type `2048` into the input box on the right. (2GB is a healthy amount of RAM for *Ubuntu Minimal*). Once done, click `Continue`.
    6. For `Hard Drive` click `Create a virtual disk now`. Once done, click `Create`.
    7. For `Hard disk file type` click `VDI (VirtualBox Disk Image)`. Once done, click `Continue`.
    8. Select `Dynamically allocated`.  Once done, click `Continue`.
    9. **Do not edit the text input that has the location to the .vdi file.** The allocated drive space should be set to at least `20.00 GB` (You can always change this later if you require more space).  Once done, click `Create`.
11. At this point, you should have an empty machine on the left with the name: `CS Ubuntu Machine` or whatever you named it.
12. From here we need to add the `.iso` file of *Ubuntu Minimal* we downloaded earlier. This can be done by right-clicking the machine on the left and selecting `Settings...` from the drop-down menu.
13. Navigate to the `Storage` tab on the top menu and click the `Empty` CD/DVD icon under the `Controller: IDE` on the left.
14. Beside `Optical Drive` make sure it says `IDE Secondary Master`. Also, click on the checkbox that says `Live CD/DVD` if it isn't checked already.
15. Click on the CD/DVD icon beside `Optical Drive` and select `Choose a disk file...` in the drop-down menu. Navigate to your `Downloads` folder, select the `mini.iso` file (this is the *Ubuntu Minimal* Disk), and press `Open`.
16. Press `OK` in the settings menu and you should be brought back to the home page of the *VirtualBox* program.
17. Then, go ahead and select the machine on the left and press `Start`  on the top menu above. This should pop up a window that has *Ubuntu Minimal* booting within it. If you are presented with a screen that asks to choose your `virtual optical drive` just press `start` as `mini.iso` should already be selected. If `mini.iso` is not appearing in the input box, you might have to restart steps starting from 12.
18. At this point in your virtual machine window should be presenting you with the `Installer boot menu`. If you accidentally click the screen and a message pops up asking `You have clicked the mouse` and to `capture` it, **select `cancel`**. If you pressed `Capture` by accident press the left `cmd` button to uncapture your mouse.
19. If the screen is too small, solve this by clicking the display option on the bottom row (The row should be filled with icons. The display icon is between the gray folder icon and the film camera icon). In the drop-down menu select: `Virtual Screen 1` > `Scale to 200% (autoscaled output)`.
20. From here select `Install` on the Ubuntu boot menu by pressing `return` on your keyboard.
21. Below are the steps to setup Ubuntu:
    1. For language, choose `English`. Press the `up arrow key` or `down arrow key` to highlight an option and press `return` to select it.
    2. For the country, select `United States`.
    3. Select `No` to `Detect keyboard layout?`.
    4. Select `English (US)` for `Country of origin for keyboard`.
    5. Select `English (US)` again for `Keyboard layout`.
    6. *Wait for installation*.
    7. Leave hostname as `ubuntu` by pressing the `down arrow key` and selecting `Continue`.
    8. Select `United States` for `Ubuntu archive mirror country`.
    9. Select `us.archive.ubuntu.com` for `Ubuntu archive mirror`.
    10. **Do not enter  `HTTP proxy information`** leave it blank. Just press `return`.
    11. *Wait for further installation* (this might take a minute or two).
    12. After installation is complete, type your full name into the text field. Enter your first name with the last name; separated by a space. (e.g `Nabeel Ahmed`). Select `Continue` once you are done.
    13. The next menu should automatically type your first name in lowercase as a username, which is fine. If you don't see anything in the input field, type your first name only in **lower-case only** (e.g `nabeel`) (You can technically write any lowercase username but it is better if you can remember it so you can log in with ease). Select `Continue` once you are done.
    14. For the next menu type a password for your system. Make sure it is rememberable as you will be using it often. Select `Continue` once you are done.
    15. Re-enter your password for the next menu for verification. Select `Continue` once you are done.
    16. Select `Yes` if *Ubuntu* is properly displaying your timezone. Select `No` if it isn't and complete the steps it prompts you with fixing that.
    17. *Wait for more installation*.
    18. For the `Partitioning method` make sure to select `Guided - use entire disk`.
    19. For `Select disk to partition`, you should only have one option as we only created one drive. Select the only option. If you see multiple drives you might need to delete your virtual machine and start back at step 10 (close the *Ubuntu* virtual machine window by pressing the close button and selecting `Power off the machine`. Once you are back to the *VirtualBox*'s main page, right-click the virtual machine and select delete and then select `remove` then `Delete all files`).
    20. Finally, select `Yes` to `Write the changes to disks?`
    21. *Wait for further installation* (this might several minutes).
    22. Once the installation has completed, select `No automatic updates`.
    23. *Wait for further installation*.
    24. For `choose software to install` **do not select anything**. Just press `return`.
    25. *Wait for further installation*.
    26. Select `Yes` for `Install the GRUB boot loader to the master boot record?`
    27. *Wait for further installation*.
    28. Select `Yes` for `Is the system clock set to UTC?`
    29. *Wait for further installation*.
    30. Finally, select `Continue` for `Installation complete`.
    31. Once the virtual machine brings you back to the `Installer boot menu`, close the virtual machine window and select `Power off the machine`. The window should be gone now.
22. Once you return to the *VirtualBox* homepage, right-click your virtual machine on the left and select `Settings...`
23. Switch to the `Storage` tab and select the `mini.iso` below `Controller: IDE`.
24. On the right, click the CD/DVD icon beside the `Optical Drive` and select `Remove Disk from Virtual Drive` from the drop-down menu.
25. Press `OK` on the settings menu located at the bottom right of the menu.
26. Finally, click `Start` on the virtual machine.
27. Once a prompt for `ubuntu login` comes up type in your username (this should be just your first name lowercase).
28. For the `Password` prompt type in the password you chose.
29. If you did everything correctly, you should be logged in now and presented with a Linux shell.
30. You are done! 👏