Install Visual Studio Code on Windows: Connect to Ubuntu 20.04 in WSL2

February 17, 2023 | By Gerald | Filed in: Linux, Linux Subsystem, Windows Subsystem.
Install Visual Studio Code on Windows: Connect to Ubuntu 20.04 in WSL2

Visual Studio Code is a popular code editor used by developers worldwide. This tutorial will show you how to install Visual Studio Code on Windows and connect to Ubuntu 20.04 in Windows Subsystem for Linux (WSL2). This setup is ideal for developers who want to work on a Windows machine and still have access to a Linux environment for development purposes.

The steps for “Step 1” and “Step 2” in this content have already been covered in this blog post: https://linuxbeast.com/devops/how-to-install-ubuntu-20-04-in-wsl2-on-a-windows-10/. If you have already completed these steps, you can skip them and proceed directly to the “Step 3” guide

Step 1: Install Windows Subsystem for Linux (WSL2)

Before we can connect Visual Studio Code to Ubuntu 20.04, we need to have the Windows Subsystem for Linux installed on our Windows machine. To install WSL2, follow these steps:

  1. Open the Windows Settings app [Win+X] and go to the “Apps & features” section.
  2. Click on the “Programs and Features” link.
  3. Click on the “Turn Windows features on or off” link.
  4. Scroll down and find the “Windows Subsystem for Linux” option.
  5. Check the box next to “Windows Subsystem for Linux” and click on the “OK” button.
  6. Restart your machine when prompted.

Step 2: Install Ubuntu 20.04 in WSL2

Once you have WSL2 installed, you can install Ubuntu 20.04 in WSL2. Here’s how:

  1. Open the Microsoft Store and search for “Ubuntu 20.04“.
  2. Click on the “Get” button to install Ubuntu 20.04.
  3. Launch the Ubuntu 20.04 app once it’s installed.
  4. Complete the initial setup by creating a username and password for your Ubuntu 20.04 installation.

Step 3: Install Visual Studio Code

Now that you have Ubuntu 20.04 installed in WSL2, you can install Visual Studio Code. Here’s how:

  1. Go to the official Visual Studio Code website and download the Windows version of Visual Studio Code.
  2. Run the Visual Studio Code setup file and follow the on-screen instructions to install Visual Studio Code.
Install Visual Studio Code on Windows
Download the Visual Studio Code
During installation, under the Additional Tasks step, ensure the Add to PATH option is checked.

Step 4: Connect Visual Studio Code to Ubuntu 20.04 in WSL2

Finally, we can connect Visual Studio Code to Ubuntu 20.04 in WSL2. Here’s how:

  1. Open Visual Studio Code.
  2. Click on the Extensions button on the left-side panel.
  3. Search for “Remote WSL” and click on the “Install” button for the “Remote Development” extension.
  4. Once the extension is installed, click on the Remote Explorer button on the left-side panel.
  5. Click on the “Open Folder in WSL” button.
  6. Select the Ubuntu 20.04 installation from the list of available WSL distributions.
  7. A terminal window will open in Visual Studio Code, allowing you to interact with your Ubuntu 20.04 installation.
Connect to Ubuntu 20.04 in WSL2

Congratulations! You have successfully installed Visual Studio Code on Windows and connected it to Ubuntu 20.04 in WSL2. With this setup, you can now work with Visual Studio Code on Windows and access your Linux environment for development purposes.

I hope this blog has helped you. Feel free to leave a comment in the section below for further recommendation

SHARE THIS ARTICLE

Tags: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *