5

I'm using VS Code with WSL. To edit code in WSL, I need to navigate to the directory in WSL and then type code . to open VS Code in the same directory. It was working before, but all of a sudden I can't get this command to work. I get the error zsh: command not found: code.

Things I have tried:

  • Both Dan Lowe's and starryknight's answers to this similar question. When I tried Dan Lowe's answer, I couldn't actually find the option "Shell Command: Install 'code' command in PATH". There was no change from trying starryknight's answer of adding the VS Code bin to PATH in .zshrc (zsh is the boot shell).
  • Restarting WSL (Ubuntu 20.04).
  • Closing the VS Code app.
supernova
  • 149
  • 4
  • 17

3 Answers3

5

I have faced this problem previously. Setting up the environment variable helped me resolve this issue.

Set the environment variable to the path where binary of VS Code is located at as follows: WSL_Environment_Variable_Path_Set

This video - https://www.youtube.com/watch?v=KcFv4QesrR0, contains detailed steps for the same. Also it covers some more tips and tricks that a developer should know about WSL.

Asish Ganesh
  • 216
  • 1
  • 9
3

For anyone searching for Ubuntu 20.04 I had to do the following:

To check the correct path you can

ls /usr/share/code/code

If the above returns error like this:

# ls: cannot access '/usr/share/code/codes': No such file or directory

Open VS Code directly then check htop to see the actual path VS Code is running

htop

Then run the following with the correct path, mine is /usr/share/code/code now

sudo ln -s /usr/share/code/code /usr/bin/code
Mahad Ahmed
  • 179
  • 4
  • 7
1

Steps:

  1. Go to "Control Panel" > "User Accounts" > "User Accounts"
  2. Click on the "Change my environment variables" from the left panel
  3. Highlight the "Path" from the "User variables for " & click edit
  4. Click "New" from the "Edit environment variable windows"
  5. Add "C:\Users<user>\AppData\Local\Programs\Microsoft VS Code\bin
  6. Restart wsl
Jauhari
  • 13
  • 2