10

When I try open VS Code in WSL2 Terminal, like this:

code . 

I get the following error:

mkdir: cannot create directory {DIRECTORY} : Permission denied

When started with sudo:

sudo: code: command not found

I added VS Code to my PATH on Windows, and installed WSL-Remote

I am working on:

  • Windows 10 Pro 10.0.19041
  • WSL 2
  • Ubuntu 20.04 LTS
  • VS Code 1.47.1

1 Answer 1

4

Check the configure file(/etc/sudoers), you need to modify the secure_path to enable run VS code with sudo command.

enter image description here

Also, it is better if you put the command path into /etc/profile, so every user could run VS code.

2
  • 1
    could we get this not as picture but as selectable text?
    – ditoslav
    Commented May 18, 2021 at 19:15
  • This is what worked for me: secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/mnt/c/Programs/Microsoft VS Code/bin"
    – dikuw
    Commented Jul 12, 2021 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.