supernova
supernova

Reputation: 179

Can't open VS Code on command line

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:

Upvotes: 5

Views: 6075

Answers (3)

Jauhari
Jauhari

Reputation: 13

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

Upvotes: 1

Mahad Ahmed
Mahad Ahmed

Reputation: 309

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

Upvotes: 3

Asish Ganesh
Asish Ganesh

Reputation: 226

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.

Upvotes: 5

Related Questions