Since I installed Docker for Windows, I can’t use VirtualBox anymore because Docker requires Hyper-V active and VirtualBox can’t live happily together with Hyper-V. So I have to move all of my virtual machines from VirtualBox to Hyper-V to keep using Docker and virtual machines at the same time. In this blog, I would like to write down the steps for installing Ubuntu and Node.js on Hyper-V
1. Prerequisites
We’re going to install Ubuntu on Hyper-V. So let’s download a copy of Ubuntu ISO file from its homepage.
2. Network
To connect virtual machine in Hyper-V to the Internet, I have to config the network interfaces correctly. It depends on how our host machine connects to the internet, we’ll need a different kind of network interface. Open Hyper-V Manager, select Virtual Switch Manager…,
Now select one of 2 approaches below to create a network switch for your virtual machine, depending on how your host connects to the Internet.
- Directly to the Internet: Select External
- Behinds a proxy: Select Internal
then click on Create Virtual Switch to create a new switch. Give it a name such as Ubuntu(in the case of external) or UbuntuNAT(in the case of internal), then Apply and OK to close the dialog.
If you created an external switch, just skip the next step to section 2. In the case of the internal switch, we need to share our internet connection with the virtual machine. Open Network and Sharing Center then select Change adapter settings (or type ncpa.cpl in Windows Run), right click on your internet network interface, and select Properties.
Go to Sharing tab, tick on Allow other network users to connect… and select your created new internal switch before (e.g. UbuntuNAT), then OK. Now your virtual machine will share the internet connection with the host.
3. Create virtual machine
In Hyper-V Manager, select New –> Virtual Machine…, give it a name such as Ubuntu.
For Ubuntu, we have to choose Generation 1
Suggested startup memory is 2048MB
Connection should be selected as your created switch before (e.g. Ubuntu or UbuntuNAT)
Browse to the ISO file of Ubuntu which you downloaded before
Click Finish to create the virtual machine (VM). The new VM will be listed in Hyper-V Manager, select it and click on Start to start the VM and execute Ubuntu installation process as normal.
4. Change resolution
If you want to Ubuntu VM uses other resolution as default, open Terminal (Ctrl-Alt-T). Execute
sudo nano /etc/default/grub
Find the line starting with GRUB_CMDLINE_LINUX_DEFAULT, and add video=hyperv_fb:[the resolution you want]. For example, the resolution I want is 1920×1080, so my line ends up like this
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1920x1080"
Save the changes and quit nano. Execute
sudo update-grub
Restart the machine.
5. Install Nodejs
Don’t install default Nodejs from apt-get, you’ll get tons of errors later when trying to update it. So first purge the old one if you’ve installed it before.
sudo apt-get purge nodejs npm
For Nodejs 6.x:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs
For Nodejs 7.x:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - sudo apt-get install -y nodejs
Now you can start your development with Nodejs on Ubuntu running over Hyper-V.