Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code is not working on WSL2

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
like image 442
kubalus Avatar asked Jul 20 '20 07:07

kubalus


People also ask

How do I get VS Code to work in WSL?

Alternatively, you can open a Remote WSL window directly from VS Code: Start VS Code. Press F1, select Remote-WSL: New Window for the default distro or Remote-WSL: New Window using Distro for a specific distro. Use the File menu to open your folder.

Does Visual Studio work with WSL?

Visual Studio's WSL 2 toolset allows you to use Visual Studio to build and debug C++ code on WSL 2 distros without adding a SSH connection. You can already build and debug C++ code on WSL 1 distros using the native WSL 1 toolset introduced in Visual Studio 2019 version 16.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.

like image 196
Jack Avatar answered Nov 11 '22 23:11

Jack