Installing Ubuntu on WSL for VSCode (Windows)

Farida Momoh
7 min readFeb 23, 2023

Hello!

This is my second article on medium after much ado, lol. So I had a first solution I had wanted write on but after using it for a while. I found out it wasn’t as convenient as I’d have liked.

Let’s jump in.

I’m currently a student of the ALX Software Engineering Program and initially I used the provided Sandboxes to complete my projects. The cons where, because of the high level traffic from other students and internet connection issues you’d sometimes, if not most times, have your terminal hanging. It’s not very flexible to say the least.

As we progressed, we got a task to install Vagrant, a tool that enables users to create and configure lightweight, reproducible, and portable development environments. Now even Vagrant has it’s cons, even though I used it for a while.

It required a lot of space and took a lot of CPU resources. (I could be working on a piece of code, and my laptop would randomly turn off)

The learning curve is quite steep(Took me a little while to figure out what exactly was going on)

Its not very easy to setup and has little to no support on Windows.

So I started asking around because at this point it was getting very frustrating. The typical response was,

Install WSL Ubuntu nau, why are you stressing?

I’d remember all the stress I’d gone through just to set up Vagrant and get really discouraged to try out this new option so I’d push it aside and continue managing my ‘headache’.

Not until water spilled on my laptop and I had to take it for repairs. On it’s return, Vagrant just wasn’t working anymore. I tried every thing I knew. Tried destroying the machine and creating a new one, tried reinstalling from scratch. Nothing. So I was forced to download WSL and this is how I went about it.

Let’s start with a brief introduction on WSL gotten from my good friend, ChatGPT

“Windows Subsystem for Linux (WSL) is a feature in Windows 10 and later versions that allows you to run Linux command-line tools and applications natively on Windows.

If you’re a developer who works with Linux-based tools and applications, WSL provides a convenient way to run them on your Windows machine without the need for a separate Linux installation.

In this article, we’ll walk you through the process of installing Ubuntu on WSL and setting up Visual Studio Code (VSCode) for development.

By the end of this tutorial, you’ll be able to work with Ubuntu on your Windows machine using VSCode, giving you the flexibility and convenience of a Linux development environment without the need for a separate machine or dual boot setup.”

INSTALLING WSL ON WINDOWS.

Visit the website — https://ubuntu.com/wsl

You can either head there and continue with the tutorial provided, or stick with me. I will be providing a compilation of all I learnt from their articles.

Open PowerShell or your Command Line Prompt in your start menu and run as administrator.

At the command prompt type:

wsl --install

(Note: It is important to run as administrator or you’ll encounter an error message)

Error : The requested operation requires elevation.

If run properly, WSL will start downloading though this might take some time.

WSL Install Complete

After installation, reboot your system and re-open your command line.

INSTALLING UBUNTU.

At the command prompt type:

wsl --list --online
#PS C:\Users\pc> wsl --list --online
#The following is a list of valid distributions that can be installed.
#Install using 'wsl --install -d <Distro>'.
#
#NAME FRIENDLY NAME
#Ubuntu Ubuntu
#Debian Debian GNU/Linux
#kali-linux Kali Linux Rolling
#openSUSE-42 openSUSE Leap 42
#SLES-12 SUSE Linux Enterprise Server v12
#Ubuntu-16.04 Ubuntu 16.04 LTS
#Ubuntu-18.04 Ubuntu 18.04 LTS
#Ubuntu-20.04 Ubuntu 20.04 LTS

This command will list the available distros .

Followed by:

wsl --install -d <'Distro'>
#wsl --install -d Ubuntu-20.04

This command will install your preferred Ubuntu Distro by name. I chose Ubuntu 20.04 LTS, in my case that is the version used for my ALX Sandbox. This installation will equally take some time to complete.

Ubuntu Installed
wsl -l -v
# You can use 'wsl -l -v' to see all your currently installed distros
# and which version of WSL they are using.

CONFIGURING UBUNTU

After installation, Ubuntu will automatically prompt and ask you for username and password.

Boom! You’re in.

If Ubuntu returns an error during this initial installation, then the most common issue is that virtualization is disabled in your device’s BIOS menu. You will need to turn this on during your device’s boot sequence.

The location of this option varies by manufacturer, so you will need to refer to their documentation to find it.

(I also had to enable Virtualization in BIOS, I use a HP ProBook 650 G2. This was how went about the process. This solution should work across all HP computers using Windows 10 OS.)

How To Enable Virtualization Technology (VTX)

It is advisable to always have the latest updates so run the following commands:

sudo apt install
sudo apt upgrade
# You will be asked to provide your password for everytime you run a sudo command.

Press Y when prompted.

Optionally, you can enable systemd

According to the WSL Official Website,

In September 2022, Microsoft announced support for systemd in WSL. This long-awaited upgrade to WSL unlocks a huge number of quality of life features for managing processes and services.

This includes snapd support, which enables users to take advantage of all of the tools and apps available on snapcraft.io.

To enable systemd you will need make a small modification to /etc/wsl.conf in your Ubuntu distribution.

Run the following command and add the lines under the comment to the /etc/wsl.conf file.

sudo nano /etc/wsl.conf

#Add these lines to your file.
[boot]
systemd=true

Restart Ubuntu in your PowerShell using the command:

wsl --shutdown
# Note to do this in your PowerShell Command line and not the Ubuntu terminal.
wsl — shutdown Powershell

This command will close the terminal and you can restart by re-opening your preferred distro or the Ubuntu Terminal itself.

USING VSCODE

If you don’t already have VsCode installed, you can do that here.

Open your Vscode.

Go to ‘Extensions’ and install Remote Development .

Remote Development Extension Vscode.

Now we’re almost done. I’ll proceed to clone a repository from my GitHub on the Ubuntu Terminal to demonstrate how to use.

(You could create a random file using mkdir or clone any repo of your choice)

Once done, Navigate to your folder and use the command:

code .
# Navigate to folder using cd <'Folder Name'>

This command will automatically install the dependencies necessary to open your file in VsCode.

Once complete, Vscode will open and show all files present in that folder.

Ubuntu ls View
VsCode File Outline View

Voila!

You can now access files on your remote machine (Ubuntu) and edit on VsCode. You can also access your Ubuntu Terminal on VsCode using CTRL + SHIFT + ~

ALL DONE!

In this article, we’ve gone through the steps to install Ubuntu on Windows Subsystem for Linux (WSL) and set up Visual Studio Code (VSCode) for development.

By using WSL and VSCode, you can enjoy the benefits of a Linux development environment on your Windows machine, without the need for a separate installation or dual boot setup.

With these steps completed, you should now have a fully functional Ubuntu development environment on your Windows machine, allowing you to work with Linux-based tools and applications with ease.

I would encourage you to explore the full capabilities of WSL and VSCode for your development needs, the possibilities are wayyy more than the scope of this article can take.

I hope this article helps you and saves you all the trouble I went through trying to navigate. I also hope you enjoy reading it just as much as I did writing it. (I have a project I should be reading up resources on but here I am)

Happy Coding!

Resources Used:

Reddit, Ubuntu Official Tutorials, Google.

Edit: So after publishing this article, I had a little chat with my friend Chat-GPT and I’d like to give add Credits for the helping me shorten my title, Brief Introduction on WSL and Concluding summary. Also for help with formatting (suggested I made my paragraphs shorter for readability).

--

--

Farida Momoh

Join me on my journey tor becoming world class. I document my thoughts and processes through my articles.