24
11
Windows Subsystem for Linux (WSL) works pretty well for making most commandline Linux tools available and working on Windows without modification. However, it gets a little tricky for development, when one wants to
- Build a project using a Linux toolchain that doesn't have a well-supported Windows equivalent (Ruby, Node, etc)
- Edit files using a Windows-based GUI editor such as Visual Studio code.
The problem is that Windows apps cannot modify files inside the virtual lxss filesystem. Directly modifying these files is known to cause all sorts of issues.
Therefore, there seem to be only two suboptimal choices when it comes to using WSL for development:
Store the project under lxss (
/home/foo
). The normal toolchain works properly. However, editing is limited to either terminal-based Vim/Emacs or whatever can be run under a janky X server, which is less smooth than native editors running on Windows.Store the project under the Windows filesystem (
/mnt/c/Users/foo
). Now any Windows-based editor can be used for development. However, the Linux-based toolchain is fragile as it's not designed to be used on a "network drive", and can cause problems with file watching or databases.
Is there any way to get the best of both worlds here - that is, to be able to edit using a native Windows application, but still have the Linux toolchain work as it normally would on a local drive?
@alex wsltools can convert the Linux paths to their Windows equivalents. This way, you can open a Windows program from the Linux command line, and tell it to open a file on the Windows filesystem. – Shane Lawrence – 2019-03-01T17:36:33.540
Don't think so. https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/. Can you provide any reference that it is safe to do so?
– Alex – 2019-03-03T16:37:38.797@alex thanks for bringing this up. This is a good point to clarify. The link you shared (which is also in OP's question) is telling you not to open files in the Linux filesystem from Windows (i.e. don't use Windows apps to change things under %AppData%\lxss).
My answer and my previous comment both describe how to open Windows files inside Windows programs from the WSL command line (e.g. open "C:\Users\Username\src\example.txt" from its WSL path "/mnt/c/Users/Username/src/example.txt").
There's also a new method coming out. I've updated my answer to show the distinction and new method. – Shane Lawrence – 2019-03-03T21:48:33.183
Shane, what is the point of using the WSL if you are going to edit windows files with windows binaries? Why not just use windows? – Alex – 2019-03-04T08:41:30.810
Good news: WSL can now edit linux files without issues with Win10 1903: https://devblogs.microsoft.com/commandline/whats-new-for-wsl-in-windows-10-version-1903/
"In the past, creating and changing Linux files from Windows resulted in losing files or corrupting data. Making this possible has been a highly requested and long anticipated feature. We’re proud to announce you can now easily access all the files in your Linux distros from Windows."
@KERR that's the update I described that was previously only available in the Windows Insider Program. It's a big improvement. – Shane Lawrence – 2019-05-14T01:21:36.663