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
Check the configure file(/etc/sudoers), you need to modify the secure_path to enable run VS code with sudo command.
Also, it is better if you put the command path into /etc/profile, so every user could run VS code.
Related
I've been trying to set up the vscode code . shortcut to work in WSL. Following the instructions from the vscode website, I reinstalled vscode in windows, reinstalled the Remote-Wsl extension, made sure it was in my System Path, and tried running code . in the WSL linux distro terminal. I get the message instructing me to install it on the windows side, and asking me if I want to continue. I hit yes, but it doesn't create the code server folder in my home directory. Typing code . again does the same thing.
Does anyone know why this may be?
This is the output text:
To use Visual Studio Code with the Windows Subsystem for Linux, please install Visual Studio Code in Windows and uninstall the Linux version in WSL. You can then use the code command in a WSL terminal just as you would in a normal command prompt.
Do you want to continue anyway? [y/N]
The error message isn't just pointing out that you need to install the Windows version, but it indicates that you have the Linux version installed in WSL and should remove it.
From that, it sounds like at some point you may have installed the Linux version of VSCode in WSL, and that one is taking priority. You'll need to uninstall it in order to run the Windows version of VSCode with the "Remote - WSL" extension.
You don't mention what distribution you are running, but if it is Ubuntu, try:
sudo apt remove code # or
sudo apt remove code-insiders
Also see the uninstall doc from Microsoft.
I am working on a linux machine my work can benefit from VSCODE.
When I install and try to run VSCODE on an Ubuntu machine, I get this error:
root#ca012294dcc1:/tmp# code --user-data-dir /tmp
To use Visual Studio Code with the Windows Subsystem for Linux, please install Visual Studio Code in Windows and uninstall the Linux version in WSL. You can then use the `code` command in a WSL terminal just as you would in a normal command prompt.
Do you want to continue anyway? [y/N] y
To no longer see this prompt, start Visual Studio Code with the environment variable DONT_PROMPT_WSL_INSTALL defined.
/usr/share/code/bin/../code: error while loading shared libraries: libxshmfence.so.1: cannot open shared object file: No such file or directory
WSL is out of scope. This is not a WSL senario
Remote SSH is out of scope. I know I can connect over SSH with Visual Studio Code. But I like to replace something like VIM with code
There is no Linux GUI available. Only text mode.
Is what I am trying to do possible?
I have Ubuntu LTS 20.04 running on wsl2 in Windows, this way I'm able to compile my JS/React code and run my php server in linux and use windows to code using Visual Studio Code.
This is running great, but a strange thing is happening, I installed nvm and gulp through the Visual Studio Code terminal and if I use them on the terminal it works fine but not if I do it outside the terminal (using Windows terminal), it says not found for both gulp and nvm.
I assume VSCode is adding a few things to the PATH but I don't know what to do for them to be found by the windows terminal (outisde VSCode terminal). Screen below. On the left is the result of running nvm list inside VS Code terminal and on the right on Ubuntu terminal, which can't find.
I'm a bit confused by your question. It sounds like you're installing programs on Windows through the VSCode terminal, and then trying to run them on Windows but it's not working. But then your screenshot shows the WSL Ubuntu prompt failing to find the command. Assuming you want to run these under WSL, log in to WSL Ubuntu and run this:
find / -name nvm
If you actually want to use the Windows terminal to run the program, you'll have to find where it is installed in Windows and make sure that's in your %PATH% but this doesn't seem like it's what you're trying to do.
The correct answer was provided by the comment from MindSwipe.
On VSCODE terminal if I "echo $PATH" it has the nvm directory in it while the $PATH on WSL doesn't, I assume VSCODE alters its own terminal PATH when the tools are installed using it instead of the global WSL path.
I've changed the WSL path and it's now working, how can I present the bounty to MindSwipe ?
Somehow when I run code . inside the WSL, it simply doesn't do anything. If I which code it does return the VS Code path on windows, but still nothing happens.
Well, after some research, what really fixed the issue for me was the following:
Within the WSL terminal, type rm -r ~/.vscode-server to delete the VS Code WSL server.
Exit the terminal and from your PowerShell/Cmd, run wsl --shutdown.
Then you can log in back to your WSL and run code . and it should work normally.
I solved it following this post with slight modifications.
exit all instaces of wsl
From the power shell run wsl --shutdown
Start VS Code on Windows
Open a previously saved project which uses wsl (this is the difference)
Open wsl and run code . starts VS Code for me
Note: the issue appeared for me after upgrading to wsl2
I have on Windows10 and WSL.
vscode is installed on Windows and not on WSL.
When I open WSL and run: code I am getting following error: command not found: code
I have reinstalled vscode and also tried with vscode insider and always checked to add PATH on installation.
The env var PATH does not contain a hint where to look and I also tried "appData/Local/Programs/Microsoft VS Code/bin/code". I am getting an error message: permission denied.
A little bit too late, but in case someone comes here.
The simplest way is to create a symbolic link in /usr/local/bin
ln -s '/mnt/c/Program Files/Microsoft VS Code/bin/code' /usr/local/bin/code
You can use the which command to find where the corresponding program file of the command is stored. This is the output on my WSL:
$ which code
/mnt/c/Program Files/Microsoft VS Code/bin/code