vscode-remote-release and wsl 2 - visual-studio-code

Has anyone already tried vscode-remote-release with the pre release of wsl 2?
I am getting the following error when starting a new wsl server:
[2019-06-15 11:14:05.702] Starting VS Code Server inside WSL.
[2019-06-15 11:14:06.526] Launching C:\WINDOWS\System32\wsl.exe bash -c "./scripts/wslServer.sh 15b7c86d86319b187a5ef255c170184a8519c5af insider .vscode-server-insiders " in c:\Users\User Name\.vscode-insiders\extensions\ms-vscode-remote.remote-wsl-0.38.0
[2019-06-15 11:14:07.126] bash: ./scripts/wslServer.sh: No such file or directory
[2019-06-15 11:15:38.680] VS Code Server for WSL failed to start. No messages received for 90s
[2019-06-15 11:15:38.680] For help with startup problems, go to
[2019-06-15 11:15:38.680] https://code.visualstudio.com/docs/remote/troubleshooting#_wsl-tips

It seems wsl2 entry path problem, try execute wsl in any folder. If your shell enter your linux's user home and not the /mnt/ path to your windows's folder path.
Currently I found reboot can resolve this problem for a while

Related

WSL vscode command returning error "not found"

I have this message whenenver i try to type code .
Can someone help me please ?
Thanks in advance
Fixed it
Open VS Code on Windows
Open Extensions and then search on WSL
It should say the extension needs to be reloaded - go ahead and reload it
Open WSL and type code
This should force another upgrade of code and this time it should launch.
I just now had the same issue on WSL2 Kali. I tried everything given here: https://github.com/microsoft/vscode-remote-release/issues/2962.
My problem was VS Code was not on Kali's path. Here's how I fixed it :)
echo $PATH
# Confirm PATH is missing this:
/mnt/c/Users/wcd/AppData/Local/Programs/Microsoft VS Code/bin/
# Confirm VS Code's location then export:
export PATH=$PATH:"/mnt/c/Users/wcd/AppData/Local/Programs/Microsoft VS Code/bin/"
# It's temporarily added to path...
echo $PATH
# This should now trigger VS Code Server install,
# then open ~/ in VS Code.
code .
# If above works, make it permanent:
echo 'export PATH=$PATH:"/mnt/c/Users/wcd/AppData/Local/Programs/Microsoft VS Code/bin/"' >> ~/.bashrc
# Restart shell + test
exec "$SHELL"
code .
I solved this problem by opening windows powershell in admin mode and typing the following command:
wsl --update
Then I typed this command to force restart the WSL and all done
wsl --shutdown
I have same issue when I trying export my old wsl and move whole project to nvme ssd using new distro.
I able to run the code . on root , but when i switch to my name then it doesn't work, I guess is WSL PATH problem.
I not really familiar to the linux, the below image may easier for you to understand what i am saying.
When i use echo $PATH on wsl to compare root and my account, and i notice that VS code directory only found on root instead of my account.
So i use export PATH=$PATH:"/mnt/c/Users/ricso/AppData/Local/Programs/Microsoft VS Code/bin" to add the VS Code path to my account* and code . is working once i export this.
But the code . will not be able to run again if you restart the wsl, so we need to put in to bashrc.
But when i try to update my account's* PATH using
echo "PATH=$PATH:/mnt/c/Users/ricso/AppData/Local/Programs/Microsoft\ VS\ Code/bin" >> ~/.bashrc and restart the wsl to login my account, i notice an error msg popup when run the code .
cannot create /tmp/remote-wsl-loc.txt: Permission denied
And i found this.
https://github.com/microsoft/vscode-remote-release/issues/5389
Seem they only giving the workaround for now and hopefully can fix it soon.
*disclaimer above: this code need to run under your account instead of root
**For editing bashrc, instead of using echo and >> write to the file, you also can use code ~/.bashrc to update/edit, when you have the vscode access on wsl.
This also happens if you disable the Windows PATH on WSL. I had my VS Code working fine, then when I disable the windows PATH (by editing/creating the /etc/wsl.conf file and inserting the [interop] appendWindowsPath = false parameter) the code command stopped working.
The ek1n8 solution solves my problem, addind the export manually to the WSL Path:
export PATH=$PATH:"/mnt/c/Users/%USERNAME%/AppData/Local/Programs/Microsoft VS Code/bin"
For me adding the binary to Path was enough:
export PATH=$PATH:"/mnt/c/Users/%USERNAME%/AppData/Local/Programs/Microsoft VS Code/bin"
For me it was wsl using the wrong container:
wsl --list -v
NAME STATE VERSION
* docker-desktop-data Stopped 2
Ubuntu Running 2
I did wsl -s ubuntu
wsl --list -v
NAME STATE VERSION
* Ubuntu Running 2
docker-desktop-data Stopped 2
and it solved the problem

WSL isn't working in VS code. What could be the problem here?

Hello I'm newbie using an Linux environment and VS code.
I've used windows terminal to access on WSL2 and it worked well.
I'm trying to set up development environment but WSL isn't working in VS code.
How can I fix the problem here?
It keeps showing "VS Code Server for WSL closed unexpectedly." message.
[2020-12-03 07:24:35.010] Resolving wsl+docker-desktop, resolveAttempt: 1
[2020-12-03 07:24:35.106] Starting VS Code Server inside WSL (docker-desktop)
[2020-12-03 07:24:35.106] Extension version: 0.51.4, Windows build: 19041. Multi distro support: available. WSL path support: enabled
[2020-12-03 07:24:35.107] No shell environment set or found for current distro.
[2020-12-03 07:24:35.317] Probing if server is already installed: C:\WINDOWS\System32\wsl.exe -d docker-desktop -e sh -c "[ -d ~/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f ] && printf found || ([ -f /etc/alpine-release ] && printf alpine-; uname -m)"
[2020-12-03 07:24:37.900] Probing result: found
[2020-12-03 07:24:37.901] Server install found in WSL
[2020-12-03 07:24:37.901] Launching C:\WINDOWS\System32\wsl.exe -d docker-desktop sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" e5a624b788d92b8d34d1392e4c4d9789406efe8f stable .vscode-server 0 '}
[2020-12-03 07:24:38.017] Setting up server environment: Looking for /root/.vscode-server/server-env-setup. Not found.
[2020-12-03 07:24:38.017] WSL version: 4.19.128-microsoft-standard docker-desktop
[2020-12-03 07:24:38.017] WSL2-shell-PID: 11
[2020-12-03 07:24:38.017] Starting server: /root/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f/server.sh --port=0 --use-host-proxy --enable-remote-auto-shutdown
[2020-12-03 07:24:38.018] /root/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f/server.sh: line 12: /root/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f/node: not found
[2020-12-03 07:24:38.018] VS Code Server for WSL closed unexpectedly.
[2020-12-03 07:24:38.018] For help with startup problems, go to
[2020-12-03 07:24:38.018] https://code.visualstudio.com/docs/remote/troubleshooting#_wsl-tips
[2020-12-03 07:24:38.021] C:\WINDOWS\System32\wsl.exe -d docker-desktop -e kill 11
[2020-12-03 07:24:38.171] WSL Daemon exited with code 0
I encountered the same problem, but it was solved by restarting the WSL2 distribution. I'm using Ubuntu-20.04, so I rebooted with the following command. After reboot, reopen VS Code and hopefully your problem will be solved.
wsl -t Ubuntu-20.04
In vscode setting, Remote WSL setting >> Extension setting
Remote.WSL2:Connection Method
select wsl2VMAddress
WSL2 version 2 uses a virtual private network which is different from Windows 10 host IP. it changes its IP address every time so... if VS code running inside WSL2 can pick up the change then it might work better. otherwise, we have to disable the autogeneration of IP in WSL2 side.
In Vs Code ctrl+schift+p
Open Preferences: Open Settings (JSON)
Add "terminal.integrated.shell.windows": "wsl.exe",
Reopen terminal.
If you need to open a specific distribution, then additionally for example:
"terminal.integrated.shellArgs.windows": ["-d", "Ubuntu-20.04"],
Reopen terminal.
In vscode terminal:
which node
and pasted the path to launch.json:
"runtimeExecutable": "<path>/node/v14.15.5/bin/node",
The issue was solved in my case by opening the Ubuntu terminal and starting vscode from there. There was a missing package in wsl that I couldn't install by editing any config file from vscode. After installing that package, vscode was able to start the remote connection with wsl
Windows update disabled Virtualization in my BIOS. You can run the wsl command in PowerShell to check if the wsl environment is ok.
I encountered the symptoms of this problem after upgrading from Windows 10 to Windows 11. My actual underlying problem was that WSL was unable to mount the .vscode extensions folder in /mnt/c/users/username/. This was caused by having a custom kernel defined in .wsconfig. In order to find this problem it was also important to increase verbosity and check dmesg in the WSL environment.
See this issue for details: WSL2 Windows Drive Not Mount 4226
This happened to me after visual studio update. I opened it via terminal and it worked.
This is the new way to add WSL to your VS Code settings.json:
In VS Code ctrl+shift+p
Open Preferences: Open Settings (JSON)
Add:
{
"Ubuntu (WSL)": {
"path": "C:\\WINDOWS\\System32\\wsl.exe",
"args": ["-d", "Ubuntu"]
}
},
"terminal.integrated.defaultProfile.windows": "Ubuntu (WSL)",
}
Reopen terminal.

install vscode extension on WSL or EMR from the command line

I am trying to force install from the command line. Obviously, this is after opening WSL or ssh tunnel opened from VSCode Windows side. Tried below:
[hadoop#ip-172-31-82-184 bin]$ pwd
/home/hadoop/.vscode-server/bin/e5a624b788d92b8d34d1392e4c4d9789406efe8f/bin
[hadoop#ip-172-31-82-184 bin]$ ./code --install-extensions VisualStudioExptTeam.vscodeintellicode
./code: line 12: ./node: No such file or directory
Kind regards
Here's a simple answer. Yeh!
Just guessed & it was there all along. Auto installed by ssh-tool itself.

Permission issue with VSCode and WSL (code: command not found)

I am new to WSL and have installed VS code natively on Windows 10 with the installer. Currently, when I try to run VS Code command code from WSL, I receive the following message:
bash: /mnt/c/Users/user/AppData/Local/Programs/Microsoft VS Code/bin/code: Permission denied
Also, when I try to run VS Code Server for WSL, I am getting a similar message.
[2020-06-29 17:41:41.640] Launching C:\windows\System32\wsl.exe -d Ubuntu sh -c '"$VSCODE_WSL_EXT_LOCATION/scripts/wslServer.sh" cd9ea6488829f560dc949a8b2fb789f3cdc05f5d stable .vscode-server 0 ' in c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-wsl-0.44.4}
[2020-06-29 17:41:41.779] sh: 1: /mnt/c/Users/user/.vscode/extensions/ms-vscode-remote.remote-wsl-0.44.4/scripts/wslServer.sh: Permission denied
[2020-06-29 17:41:41.780] VS Code Server for WSL closed unexpectedly.
I have tried configuring the permissions for wsl # wsl.conf:
[automount]
enabled = true
options = "uid=1000,gid=1000,umask=022,fmask=11,metadata"
Not sure if this is relevant, but I am able to run code from Windows Powershell.
I am currently using Microsoft Windows 1909 (OS Build 18363.836) with WSL v1.
Any help will be appreciated, thanks in advance!
Run wsl.exe or PowerShell as an Administrator Runs as Admin Windows
None of the previous answers worked for me. Instead after a lot of trial and error, I discovered that the code.exe was set in a way that it was being run as Administrator. This is what prevented it from running in the WSL. Find the VC Code executable, and ensure it doesn't have the admin Shield on it's icon.
It has to do with your /etc/wsl.conf. Change the contents of the file to:
[automount]
enabled=true
root = /
options="metadata,uid=1000,gid=1000,umask=002,dmask=002,fmask=002"
umask,dmask, and fmask all have to do with permissions. A pretty good explanation of them can be found here : https://askubuntu.com/questions/429848/dmask-and-fmask-mount-options#:~:text=fmask%20and%20dmask%20are%20mount,files%20and%20dmask%20to%20directories
Maybe for someone will helpfull...
For example i have mistake like this:
$ code .
/c/Users/admin/AppData/Local/Programs/Microsoft VS Code/bin/code: line 61: /c/Users/admin/AppData/Local/Programs/Microsoft VS Code/Code.exe: Permission denied
My error resolving was by click right button mouse on icon VS Code and chosen settings then "compatibility" tab and finaly disabled "run the program as an administrator"
I solved it by putting my Ubuntu user in the www-data group. I edited the /etc/group. That www-data group is the one in my configuration belongs to Apache2. Hope this helps.

WSL2 terminal does not recognize Visual Studio Code

When I try to execute code from WSL, like this:
cmd.exe
wsl code .
I get the following error:
/bin/bash: code: command not found
However, if I execute the same command but first run cmd.exe as an Administrator, vscode opens as expected.
The question is why "code" is not recognizable when I run as non-admin, and how can I solve it?
Additional info:
WSL2 version 41959
vscode version 1.38
vscode Remote WSL extension version 0.39.5
As #Biswapriyo mentioned, this is an open bug where WSL cannot access Windows C drive.
Workaround that helped me is to restart WSL like this:
wsl --shutdown
wsl
Open the PowerShell administrator window
wsl --list --version
Show as wsl 2
Enter the Linux console
wsl
Change related files' rights
chmod u+x vscode_dir/code.exe
chmod u+x vscode_dir/bin/code
Create symbolic link
ln -s vscode_dir/bin/code code
mv code ~/.local/bin
Modify .bashrc, add a line as follows:
export PATH="$HOME/.local/bin:$PATH"
source .bashrc or restart terminal.
Then you can happily play code in wsl2-ubuntu environment or terminal of VSCode.
My problem was that I was using the root user after running sudo -i. Exiting and using my normal user on WSL solved the error.
In my case I am using Debian and echo %PATH% did not output anything.
I used the second part of suggested solution from resolved github issue
For Debian, /etc/profile contributed to this problem.
Here is the path definition in /etc/profile
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
Option 1:
You can delete above lines, then wsl --shutdown to restart Debian.
Option 2:
If you would like to keep these lines, you can also append ":$PATH" to each path like below, then wsl --shutdown
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:$PATH"
fi
Thank you to licanchua
I'd recommend checking /etc/wsl.conf to see if appendWindowsPath setting shares the Windows PATH with WSL, and also if it is specifically setting a particular user.
For the config settings, see https://learn.microsoft.com/en-us/windows/wsl/wsl-config