Launch VS Code from WSL Bash

早过忘川 提交于 2019-12-12 08:19:28

问题


I have the Creators update installed. WSL is operational. I can execute most .exe files by simply calling notepad.exe But when it comes to VS Code.... I can't use the default code command or call code.exe... I have also tried code and code.cmd. Why doesn't VS Code execute like other programs? And is there a way to enable the code command?

EDIT: I now get these errors:

me@mypc:/mnt/c/Users/me/Documents/project_folder$ code . /mnt/c/Program Files (x86)/Microsoft VS Code/bin/code: line 7: realpath: comma nd not found /mnt/c/Program Files (x86)/Microsoft VS Code/bin/code: line 14: ./Code.exe: No such file or directory


回答1:


The Creators update did install the interop functionality. However, it seems you need to install realpath in WSL in order for the path to be recognized. I'm not sure why this is the case but running sudo apt-get install realpath fixed it for me!

EDIT: After updating to the Fall Creators Update launching VSCode from WSL works out of the box 🎉




回答2:


You could always create an alias in the WSL Bash shell

alias code="/mnt/c/Program\ Files/Microsoft\ VS\ Code/Code.exe"

If you add this to your .bashrc or .zshrc file then it will always be available when you start a new instance of your environment.




回答3:


WARNING: Do not change Linux files using Windows apps and tools

Update: The above is not relevant to version 1903 or newer.

With that out of the way, I recently experienced the exact same behavior. Turns out, in my noobish first whack at WSL with VS Code I also installed a native copy from apt which overwrote the Windows path.

So in WSL I removed it with something like this...

$ sudo apt remove code -y; sudo apt autoremove -y

Then confirmed the path was correct...

$ which code
/mnt/c/Program Files/Microsoft VS Code/bin/code

Then relaunched WSL terminal and all was well in the wonderful world of coding once again. :)

Note: I suppose another option would be to fix the path in WSL, but without a GUI package installed it will just launch in the background and never appear anyway.



来源:https://stackoverflow.com/questions/43640023/launch-vs-code-from-wsl-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!