In this section, we will see how to set up Linux (Ubuntu) on a virtual machine, so that a Windows user can also develop and test their .NET Core 2.0 applications in Linux. To do so, let’s start with the VirtualBox setup. Oracle provides an open source VirtualBox executable, which we downloaded in the previous section. The following are the steps we need to follow to set up VirtualBox:
- Double-click on the VirtualBox executable. It will open a wizard. Before installation, click on
Disk usage
and checkDisk Space Requirement
. It is recommended that the virtual machine for Ubuntu Linux is set up with at least 2 GB RAM and 25 GB free hard drive space. So, instead of choosing the default drive (theC
drive in our case, where Windows is installed), select another drive if it exists (for example, theD
drive) so that you can easily allocate more space, and it also prevents any impact on the host operating system. - The VirtualBox setup needs approximately 241 MB of disk space to install. It's recommended to create a new folder (for example,
VirtualBox
) to easily identify and track the VM.
- Keep clicking the
Next
button until the last page. At the end, a warning will be displayed that the installation of VirtualBox will reset the network connection and temporarily disconnect the machine from the network. This is alright if you are working on the same physical machine. So, click on theYes
button and continue, and then click on theInstall
button and finish the installation:
- Once the preceding installation is done, open the VirtualBox manager to create a new virtual machine. Click on
New and give the
:Name
of the machine (for example,Ubuntu
, as shown), and select theType
asLinux
and theVersion
asUbuntu (32 bit)
- We need to specify the memory size. More memory is good, but we should consider our disk space before selecting it. A minimum of 2 GB system memory is required for Ubuntu 17.04. Select
Create
and then selectVDI (VirtualBox Disk Image)
asHard disk file type
. Select aDynamically allocated
hard disk. It will use space on your physical hard disk as it fills up (up to the maximum fixed size). Set the disk space maximum size to25 GB
and click onCreate
. It will create a virtual machine with the Ubuntu operating system (32-bit) and 4 GB RAM, and the full details will be displayed on the final page:
For Windows machines, we can use Hyper-V to create a Linux virtual machine. Let's start with the basic settings and important configuration changes:
- First, enable
Hyper-V Management Tools
andHyper-V Platform
fromWindows Features
:
- Change the default virtual directory. By default, Hyper-V uses the same drive as that on which the OS is installed but this is not a good practice. We should change the default drive the drive on which the operating system is not installed, such as the
D
drive in our case. It's a good practice to keep Windows and system files separate from other files. To make configuration changes, openHyper-V Manager and then
. Instead of the default selection, change it to some other drive (Hyper-V Settings
D
in our case). Create a new folder namedVirtual Machine
on this new drive location:
- Create a virtual switch. A virtual switch is used to join computers and to create networks. We can create three types for virtual switches:
External
: An accessible network where the virtual machines are hosted on the same physical computer and all external servers from which the host machine can connect.Internal
: Creates a virtual switch that can be used only by the virtual machines that run on the same physical computer, and between virtual machines and the physical computer. An internal virtual switch doesn't provide connectivity to a physical network connection.Private
: Creates a virtual switch that can be used only by the virtual machines that run on the same physical computer.
Create a Private
or External
type of virtual switch. This will be used for the virtual machine:
Open Network and Sharing Center
on your host machine and then open the external virtual switch properties. You will find Hyper-V Extensible Virtual Switch.
This provides network connectivity to the virtual machine. Enable this or the virtual machine won't be able to connect to the host machine network:
- Create a new virtual machine, and choose the name and location for the virtual machine. Select
Generation 1
on the next page and selectExternal Virtual Switch
. Select theInstall an operating system from a bootable CD/DVD-ROM
option and selectImage file (.iso),
which we downloaded earlier for Ubuntu. Continue clicking theNext
button in the wizard and the Ubuntu virtual machine will be created. Click onStart
and connect to it:
- After connection, we will be able to see the following screen. Select
Install Ubuntu
and set the language asEnglish
. Choose theErase disk and install Ubuntu
option and then clickContinue
:
- Provide the username and password that you want and click
Continue
. Restart the system once the installation is done:
After restarting the virtual machine, it will display a login page. Enter the password that you provided while installing Ubuntu. On successful login, it will open the homepage, from where we can start Visual Studio Code and .NET Core 2.0 SDK installation on this Ubuntu machine.