Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Running code . in WSL does nothing, or VS Code will not connect to WSL

Errorcode: command not found

Short answer

Typing code . in WSL needs the VS Code bin folder on the WSL PATH, the WSL extension in VS Code, and a distro that can download the VS Code Server. Check echo $PATH first. Then confirm the extension, the right command, the default distro, and wget with ca-certificates.

  • Applies to VS Code with WSL extension, WSL 2, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the VS Code bin folder is on the PATH WSL sees, and which distro is the default.

    echo $PATH | tr ':' '\n' | grep -i code
    wsl.exe -l -v
  2. 2Match what you see, then jump to its fix

    1. 1code: command not found, only in the WSL terminalThe VS Code bin folder is not on the WSL PATHFix
    2. 2code is not found but code-insiders is, or VS Code opens as a plain Windows windowYou use VS Code Insiders, or the WSL extension is not installedFix
    3. 3The window shows 'Installing VS Code Server' and then a connection errorThe VS Code Server install fails inside the distro (missing wget or certificates)Fix
    4. 4'WSL: New Window' opens a distro other than the one you are working inVS Code connects to a different distro than you expectFix

What does the error look like?

  • code: command not found
  • VS Code opens but cannot connect to the WSL distro
  • VS Code shows a message that it is installing VS Code Server, then fails

Cause 1 of 4

The VS Code bin folder is not on the WSL PATH

1Check

VS Code docs say to look for its bin folder in echo $PATH. It is missing if Windows path sharing is off, or if VS Code was not added to PATH when it was installed.

echo $PATH

2Fix

Restart the terminal first. If Windows path sharing is disabled, add the Windows System32 folder and the VS Code bin folder in ~/.bashrc, quoting spaces, and open a new terminal.

# ~/.bashrc  (replace <user> with your Windows user name; quote folders with spaces)
export PATH="$PATH:/mnt/c/Windows/System32:/mnt/c/Users/<user>/AppData/Local/Programs/Microsoft VS Code/bin"

3Verify

code resolves to the VS Code launcher.

exec bash
which code

Confirmed by code.visualstudio.com

Did this fix it?

Cause 2 of 4

You use VS Code Insiders, or the WSL extension is not installed

1Check

The WSL tutorial says Insiders uses code-insiders, and that the Remote - WSL extension (ms-vscode-remote.remote-wsl) must be installed in VS Code.

which code-insiders
which code

2Fix

Run code-insiders . if you use Insiders. Otherwise open the Extensions view in VS Code on Windows, install the WSL extension (ms-vscode-remote.remote-wsl), and run code . again.

code-insiders .

3Verify

code . in the WSL terminal opens VS Code attached to WSL.

code .

Confirmed by code.visualstudio.com

Did this fix it?

Cause 3 of 4

The VS Code Server install fails inside the distro (missing wget or certificates)

1Check

Microsoft's guide lists wget and ca-certificates as missing libraries on Debian and Ubuntu. Run WSL: Show Log in VS Code for the actual error.

command -v wget; dpkg -s ca-certificates | head -n 2

2Fix

Install them inside the distro.

sudo apt-get update && sudo apt-get install wget ca-certificates

3Verify

Run code . again; the server installs and the window connects.

code .

Confirmed by code.visualstudio.com

Did this fix it?

Cause 4 of 4

VS Code connects to a different distro than you expect

1Check

The troubleshooting page says WSL: New Window opens the default distro, and that you open another by running code . from that distro's shell.

wsl.exe -l -v

2Fix

Run code . from the shell of the distro you want, or use WSL: New Window using Distro.

# inside the wanted distro:
code .

3Verify

The bottom-left status bar shows the expected distro name.

cat /etc/os-release | head -n 2

Confirmed by code.visualstudio.com

Did this fix it?

How do I stop it coming back?

  • Tick the add-to-PATH option when installing VS Code on Windows.
  • Update WSL from time to time with wsl.exe --update.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.