I've recently set a working copy of Ubuntu-20.04 WSL2 called Ubuntu-20.04-copy01 but I can't open/create files with vscode from the terminal, for example: code main.rs as with the original distribution.

The output of echo $PATH:


The original distro output of the same command is

/home/rogelio/anaconda3/bin:/home/rogelio/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:/mnt/c/Users/rogel/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/rogel/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin

Would it be enough if I configure the .bashrc file of my copy of ubuntu to add /mnt/c/Users/rogel/AppData/Local/Programs/Microsoft VS Code/bin?

I'm not sure if this would create conflicts.

I also changed the default distro used by wsl using wsl --setdefault Ubuntu-20.04-copy01.


1 Answer 1


By default, the WSL init process that runs when the instance is started is supposed to append the Windows path to the Linux $PATH. It seems that either (a) that's not happening for some reason, or (b) something in your startup files is modifying it after the fact.

A few things to check:

  • First, try launching that instance via wsl -d Ubuntu-20.04-copy01 -e bash --noprofile --norc. Does code . work then? Does echo $PATH look different than before? If so, then something in the startup files is to blame. Look for anything in ~/.bashrc or ~/.bash_profile (or any other startup files or referenced files) that might be modifying $PATH.

  • If that's not it, then create or modify /etc/wsl.conf (with sudo) with the following settings:


    That's supposed to be the default, but if it was set to false, that could cause the problem. Regardless, let's just force it to true to be sure.

    You'll need to shut down the instance and restart for it to take effect, so:

    • Exit any shells running
    • From PowerShell or CMD: wsl --terminate Ubuntu-20.04-copy01
    • Restart and check your $PATH and try code . again

To answer your follow-up question, yes, you could manually append ...VSCode/bin to your $PATH in your startup files, but I would personally recommend fixing the core problem instead. Being able to run Windows apps easily opens up a lot of possibilities. For instance, you can run PowerShell commands via powershell.exe (e.g. powershell.exe get-childitem HKCU:). You can even run the wsl.exe command from within WSL to use root-level commands with the need for a sudo password (e.g. wsl.exe -u root service cron start).

  • Thanks, it worked! I upvoted your answer but I need at least 15 reputation to publicly cast a vote. Aug 21, 2021 at 0:14
  • No worries - When you get some more rep, the vote will end up counting retroactively. Great to hear it worked! Which part was it -- the shell config or the wsl.conf? Aug 21, 2021 at 0:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .