How To Install Ubuntu Linux on Windows Using WSL2 and Use VSCode
6 May, 2023
0
0
0
Contributors
Introduction
If you've ever wanted to try out or completely switch to Linux or use Linux for development reasons but didn't want to go through the process of installing another operating system or using a VMware, you're in luck because you can do just that using WSL2 for Windows.
Windows Subsystem for Linux (WSL) allows you to install a complete Ubuntu terminal environment in minutes on your Windows machine, allowing you to develop cross-platform applications and enjoy other things that could normally only be done on Linux without leaving Windows. For this example, we're going to be installing Ubuntu with WSL.
Ubuntu can be a good choice for users who value open-source software, customizability, security, stability, and performance.
Here are the steps to install Ubuntu on Windows using WSL2:
Prerequisite
First, you need to ensure your computer meets the minimum requirements; otherwise, things may not work as expected. It is recommended to have at least Microsoft Windows version 2004 or above. You can check your Windows version by opening a command line and typing "winver". A window should pop up to tell you about your Windows version. If you're on Windows 11, then this should work fine. If you're on a previous version, you can use Windows Update to update your PC.
STEP 1
You need to enable virtualization on your windows pc. To do this, press the Windows key, then search the Windows start menu for "Turn Windows features on or off". Open that and from the list of items enable "Windows Subsystem for Linux" and "Virtual Machine Platform". Then click OK. This will apply the changes but cause your PC to need a reboot. Click on "Restart now," and when that's done, we can get to Step 2.
STEP 2
Use the Windows key, then search the start menu for PowerShell then right-click it and select run as an administrator. In the shell, you can check if you have WSL by typing "wsl". Use "wsl --update" to install the latest version of WSL. After that's done, we can check for which Linux kernels we can get by typing "wsl --list --online". To get Ubuntu, you have to type "wsl --install -d Ubuntu".
STEP 3
Now we should be able to find an Ubuntu kernel installed on our computer. You can find the application by searching for it on the Windows start menu. The first launch after installation, Ubuntu will set itself up and request a username and password. Type these in and make sure you don't forget these by writing them down somewhere- you will need your password to authorize some operations on Ubuntu.
STEP 4
As a best practice, to ensure everything is up to date and to make sure we have all the latest security features, we type "sudo apt update". When that's done, we use "sudo apt upgrade " to install those updates. Reboot the instance of Ubuntu by using "wsl.exe --shutdown". Open another instance of Ubuntu from the Windows search menu, and if you followed the instructions well your kernel should be working fine. And that's it - you now have an Ubuntu kernel on a Windows PC.
If you want to check if everything is working correctly, you can test it by running "sudo apt install gimp -y". Put in your password, and after it has been installed, you should be able to run GIMP by typing "gimp".
VSCODE ON WSL
Now, let's talk about how to use VSCode for developers who want to build on Linux.
First of all, you need to have VSCode installed on your Windows system. You can do this by following the instructions here.
After you have installed VSCode, navigate to the Extensions tab and install the "Remote Development" extensions pack by Microsoft. This allows you to open a WSL Ubuntu instance of WSL. You can do this using the Command Palette, which can be accessed with the shortcut "Ctrl + Shift + P," and then selecting "Remote WSL Window". This opens up a new instance of WSL for windows
CONCLUSION
By following the steps outlined in this guide, users can easily install Ubuntu on their Windows computer using WSL2, and then use Visual Studio Code to start developing on Linux. Overall, WSL2 can be a powerful tool for users who want to run Linux-based applications on their Windows computer, without the need for a separate operating system installation or virtual machine.