What is the path of code for wsl, hence Vscode installed in users profile
Asked Answered
M

3

6

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.

Malachite answered 1/9, 2019 at 12:54 Comment(0)
C
11

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
Coalition answered 14/11, 2020 at 14:46 Comment(3)
FWIW on my machine, VS Code is now installed inside the AppData/Local path. This means that the command you should enter is ln -s "/mnt/c/Users/<username>/AppData/Local/Programs/Microsoft VS Code/bin/code" "/usr/local/bin/code" I think you should be able to tell which situation you're in by first issuing ls "/mnt/c/Program Files/Microsoft VS Code/bin/code". If there are no folders/files found, check the AppData/Local path instead and create the link to wherever VS code is installed.Resolution
If anyone uses VS Code Insiders. Then the command should be eg.: ln -s "/mnt/c/Users/<username>/AppData/Local/Programs/Microsoft VS Code Insiders/bin/code-insiders" /usr/local/bin/code-insiders. Obviously this way your command should be code-insiders.Radloff
This approach does not use the IPC, so the behavior is sub-optimal.Harmsworth
H
0

The preferred answer will work, but also sub-optimal and won't work if you are in an ssh remote linux host, if you follow those instructions you'll have other odd behaviors because it isn't aware of the IPC, for example you can't open a file in an existing vscode window, it will open in a new window - which is both annoying and slow.

The TLDR is you probably want: https://github.com/chvolkmann/code-connect

I'll try to explain what this does:

There is a ~/.vscode-server where vscode sets up an IPC, if you echo $VSCODE_IPC_HOOK_CLI you'll see something like:

echo $VSCODE_IPC_HOOK_CLI 
/run/user/1000/vscode-ipc-b9c6c65d-7cdb-4169-ba06-caafb62e77f4.sock

The problem is, the path changes for each vscode-server instance, but inside the dir /run/user/1000/xxxx/bin/code you'll find youur code.

If you find that code, then run code --locate-shell-integration-path bash you'll see it output where to find the shell hooks, anyway there is a convoluted CLI which uses the VSCODE_IPC_HOOK_CLI + awk and then transmutes this into the vscode path, which is the same thing chvolkmanns code-connect does, so I use that.

once you have code setup at the IPC integration is very slick, you can also:

# add this .bashrc
export EDITOR="code -w -r"
# run this to setup GIT to use vscode
git config --global core.editor "code --new-window --wait"
Harmsworth answered 5/2 at 4:18 Comment(0)
A
-1

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
Archuleta answered 1/9, 2019 at 15:3 Comment(2)
Actually you are just pointing out the problem. Would you like to read my question again, or should I explain it again? In WSL: running code results into error message command not found now I can not locate the code command. Vscode is on Windows10 installed, but the env PATH in WSL is not set to find codeMalachite
This may not answer your question directly, but I feel that it does point us in the correct direction. In my case, checking the folder "/mnt/c/Program Files/Microsoft VS Code" helped me realize that after updating code the location of the executable had changed to "/mnt/c/Users/<username>/AppData/Local/Programs/Microsoft VS Code/bin/code". What concerns me now is how this folder is added to my path in the first place :/Booty

© 2022 - 2024 — McMap. All rights reserved.