A Step-by-Step Guide to Adding Ubuntu (WSL) in VS Code Terminal

A Step-by-Step Guide to Adding Ubuntu (WSL) in VS Code Terminal

If you’re working on Windows and want to harness the power of Linux alongside your development environment, integrating Ubuntu (WSL) into the VS Code terminal is a seamless way to do so. In this blog, we’ll walk you through the entire process—from setting up prerequisites to configuring Ubuntu in your VS Code terminal.

Prerequisites

Before we start, ensure the following:

  1. Windows 10/11 Installed

    • You need a Windows machine running at least version 1903 or higher for WSL 2.

    • To check your version, run winver in the Start Menu.

  2. Visual Studio Code


Step 1: Install WSL on Windows

1.1 Enable WSL

  1. Open PowerShell as Administrator.

  2. Run the following command to enable WSL:

     wsl --install
    
  3. Restart your computer if prompted.

1.2 Verify Installation

After the restart, verify that WSL is installed by running:

wsl --list --verbose

You should see a list of installed distributions with their states.

1.3 Set WSL as Default (Optional):

  • To ensure WSL is the default shell for your terminal, you can use:

      wsl --set-default Ubuntu
    
  • This ensures that running the wsl command will always open your Ubuntu distribution.

1.4 Varify working of WSL

  • Run below command in your local terminal (CMD,PowerShell).
wsl


Step 2: Install VS Code Extensions

To integrate WSL with VS Code, install the following extensions:

  1. WSL

    • Open VS Code.

    • Go to the Extensions view by clicking the Extensions icon on the left sidebar (or press Ctrl+Shift+X).

    • Search for “WSL” and click Install.


Step 3: Configure Ubuntu (WSL) in VS Code Terminal

To set up Ubuntu (WSL) in the VS Code terminal:

3.1 Open settings.json

  1. Open VS Code.

  2. Press Ctrl+Shift+P and type “Preferences: Open Settings (JSON).”

  3. Select it to open the settings.json file.

3.2 Add Terminal Profiles

Add the following configuration for Ubuntu (WSL):

{
    "workbench.iconTheme": "vscode-icons",
    "editor.mouseWheelZoom": true,
    "terminal.integrated.fontSize": 15,
    "explorer.confirmDelete": false,
    "files.autoSave": "afterDelay",
    "terminal.integrated.profiles.windows": {
        "Ubuntu (WSL)": {
            "path": "C:\\WINDOWS\\System32\\wsl.exe"
        }
    },
    "terminal.integrated.defaultProfile.windows": "Ubuntu (WSL)"
}

3.3 Save and Reload VS Code

  1. Save the changes to settings.json.

  2. Reload VS Code by pressing Ctrl+Shift+P and typing Reload Window.


Step 4: Test the Configuration

  1. Open the terminal in VS Code by pressing Ctrl+` (backtick).

  2. Click the dropdown menu in the terminal tab.

  3. Select Ubuntu (WSL).

  4. You should see a terminal that looks like this:

     amitabh@Amitabh-Laptop:~$
    

Troubleshooting Tips

  1. WSL Not Recognized

    • Ensure WSL is installed and Ubuntu is set up. Run wsl --install -d Ubuntu if needed.
  2. Ubuntu Not Listed in Terminal Dropdown

    • Double-check the settings.json file for typos.

    • Restart VS Code after saving changes.

  3. Extensions Not Working

    • Ensure the “WSL” extension is installed and enabled.

Conclusion

With Ubuntu (WSL) configured in VS Code, you can now work seamlessly in a Linux environment directly from your Windows machine. Whether you’re developing web apps, testing scripts, or running Docker containers, this setup will make your workflow more efficient. Happy coding!