13

I was configuring the new Windows subsystem for Linux 2 developing environment. I have installed VSCode in Windows and WSL2 distribution of Ubuntu 18.04. I can open VSCode in Ubuntu(accessed through Windows Terminal) normally when logged as normal user, using command as follows:

simp1e@ZhuXian:/mnt/c/WINDOWS/system32$ code . 

But when I add sudo command in the front, the error occurs as follows:

simp1e@ZhuXian:/mnt/c/WINDOWS/system32$ sudo code .
sudo: code: command not found                                                                                                                                                           

At first, the problem remains after I switched to root user. Later I found that the PATH of root user didn't contain VSCode. So I add the VSCode path to /etc/environment. After that root user can open VSCode normally, but sudo code . still have the problem. What should I do? Is this still related to the PATH?

Yunchou Li
  • 181
  • 1
  • 4
  • 1
    What are you trying to do? running `code` from WSL usually starts Window's vscode (on regular privilege). You would need WSL host to be on administrator mode and then `code` would be privileged (Windows-wise). What is the output of `which code`? – idanp Jul 30 '19 at 18:57
  • You ever figure this out? – mpen Jan 16 '20 at 05:31
  • I've answered this here: https://stackoverflow.com/questions/58980356/vscode-in-wsl-how-to-sudo-a-root-file-so-i-can-edit-it/61984421#61984421 . This is probably a duplicate (Although technically you asked the question first) – Lance May 24 '20 at 10:32

1 Answers1

1

The answer here helped me: VSCode in WSL: how to sudo a root file so I can edit it

For some reason starting as root vs logging in and then switching to root worked for me

nessa
  • 337
  • 2
  • 16