Visual Studio Code is not working on WSL2

Viewed 1923

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 Answers

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.

Related