How to set up VS Code with WSL 2 on Windows 10/11

Windows Subsystem for Linux is powerful, but if you integrate Visual Studio Code on your Windows PC with WSL's kernel, you can do a lot in less time and in a better way.

Microsoft's Visual Studio Code is very popular and loved by the developer community. Windows Subsystem for Linux is powerful, but if you integrate Visual Studio Code on your Windows PC with WSL's kernel, you can do a lot in less time and in a better way.

The following article will discuss WSL and how you can set up VS Code on Windows for a seamless workflow.

Why use Visual Studio Code with WSL 2?

VS Code is a powerful integrated development environment (IDE) created by Microsoft that supports all kinds of programming languages. Developers prefer to use Visual Studio Code because it works on almost any platform, including macOS, Linux, and Windows. It also has a large community dedicated to building great extensions that make development easier.

Picture 1 of How to set up VS Code with WSL 2 on Windows 10/11

As a developer, the ability to use Visual Studio Code to develop applications on the Windows platform and run those applications on the Linux kernel is an incredibly handy feature and offers amazing benefits.

When integrating VS Code into the Windows Subsystem for Linux, you can use its specialized Linux kernel to enhance cross-platform compatibility. You can further streamline your workflow using the built-in terminal in VS Code with WSL 2.

How to integrate WSL 2 with Visual Studio Code

Although the Windows Subsystem for Linux provides a dedicated Linux kernel so you can run your applications, you cannot directly edit the code through its terminal. Fortunately, you can ease the workflow by configuring Visual Studio Code to integrate with your WSL 2 Linux distribution.

How to install Visual Studio Code

As a prerequisite, you must first make sure VS Code is set up correctly on your Windows PC. Installing VS Code is simple and straightforward, but if you're unsure, you can check out TipsMake's beginner's guide to setting up Visual Studio Code on a Windows PC:

1. Go to the following link and download the Windows installer.

2. When the download is complete, run the setup setup.

3. Click Next until you see the Select Additional Tasks step and make sure the Add to PATH option is selected.

Picture 2 of How to set up VS Code with WSL 2 on Windows 10/11

 

4. Complete the installation wizard.

If you have VS Code installed, you need to make sure you can use the terminal to open a folder in VS Code:

  1. Launch VS Code from the Desktop or Start menu.
  2. Select Ctrl + Shift + P to open the Command Palette .
  3. In the search box, type shell command and look for the option Shell Command: Install "code" command in shell PATH .
  4. Select the option if you can see it. This will allow you to open a folder in Visual Studio Code from the command line.

If the option does not appear, then the VS Code profile is enabled on your PC.

How to configure VS Code with WSL 2

Once you've made sure VS Code is set up properly on your Windows PC, you can safely connect VS Code to Windows Subsystem for Linux 2:

1. You can move on to the next step if you already have WSL 2 configured on your system. If not, download Ubuntu from the Microsoft Store to get started.

2. Launch the Start menu, search for Visual Studio Code and select the best match.

3. From the side menu pane, click the Extensions icon or use the keyboard shortcut Ctrl + Shift + X to view installed extensions.

4. In the Search Extensions in Marketplace field , search for WSL , select the best match and click Install .

Picture 3 of How to set up VS Code with WSL 2 on Windows 10/11

5. Once the extension is installed, launch your WSL 2 distribution (in the case of Ubuntu) via the Start menu. You can also open it via the new Windows Terminal.

6. Navigate to the project folder in WSL 2 with the cd command and then enter the following command to open the folder in VS Code:

code .

7. VS Code now opens your source code in a Windows environment but allows you to debug and test your application in a Linux environment.

If you are a developer who is not completely satisfied with Linux but still need to use it for work, the article really recommends getting familiar with WSL 2. It's an amazing tool that will get better and better. in the coming years.

Update 14 April 2023
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile