Running code . in WSL does nothing, or VS Code will not connect to WSL
code: command not foundShort 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.
Fix it fast
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 -v2Match what you see, then jump to its fix
- 1
code: command not found, only in the WSL terminalThe VS Code bin folder is not on the WSL PATHFix - 2
code 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
The 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
'WSL: New Window' opens a distro other than the one you are working inVS Code connects to a different distro than you expectFix
- 1
What does the error look like?
code: command not foundVS Code opens but cannot connect to the WSL distroVS 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 $PATH2Fix
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 codeConfirmed by code.visualstudio.com
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 code2Fix
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
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 22Fix
Install them inside the distro.
sudo apt-get update && sudo apt-get install wget ca-certificates3Verify
Run code . again; the server installs and the window connects.
code .Confirmed by code.visualstudio.com
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 -v2Fix
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 2Confirmed by code.visualstudio.com
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 fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix