Cool WSL (Windows Subsystem for Linux) tips and tricks you (or I) didn't know were possible
It's no secret I dig WSL (Windows Subsystem for Linux) and now that WSL2 is available in Windows Insiders Slow it's a great time to really explore the options that are available. What I'm finding is so interesting about WSL and how it relates to the Windows system around it is how you can cleanly move data between worlds. This isn't an experience you can easily have with full virtual machines, and it speaks to the tight integration of Linux and Windows.
Look at all this cool stuff you can do when you mix your peanut butter and chocolate!
Run Windows Explorer from Linux and access your distro's files
When you're at the WSL/bash command line and you want to access your files visually, you can run "explorer.exe ." where . is the current directory, and you'll get a Windows Explorer window with your Linux files served to you over a local network plan9 server.
Use Real Linux commands (not Cgywin) from Windows
I've blogged this before, but there are now aliases for PowerShell functions that allow you to use real Linux commands from within Windows.
You can call any Linux command directly from DOS/Windows/whatever by just putting it after WSL.exe, like this!
C:\temp> wsl ls -la | findstr "foo"
-rwxrwxrwx 1 root root 14 Sep 27 14:26 foo.bat
C:\temp> dir | wsl grep foo
09/27/2016 02:26 PM 14 foo.bat
C:\temp> wsl ls -la > out.txt
C:\temp> wsl ls -la /proc/cpuinfo
-r--r--r-- 1 root root 0 Sep 28 11:28 /proc/cpuinfo
C:\temp> wsl ls -la "/mnt/c/Program Files"
...contents of C:\Program Files...
Use Real Windows commands (not Wine) from Linux
Windows executables are callable/runnable from WSL/Linux because the the Windows Path is in the $PATH until Windows. All you have to do is call it with .exe at the end, explicitly. That's how "Explorer.exe ." works above. You can also notepad.exe, or whatever.exe!
Run Visual Studio Code and access (and build!) your Linux apps natively on Windows
You can run "code ." when you're in a folder within WSL and you'll get prompted to install the VS Remote extensions. That effectively splits Visual Studio Code in half and runs the headless VS Code Server inside Linux with the VS Code client in the Windows world.
You'll also need to install Visual Studio Code and the Remote - WSL extension. Optionally, check out the beta Windows Terminal for the best possible terminal experience on Windows.
Here's a great series from the Windows Command LIne blog:
You can find the full series here:
- Part 1 Take your Linux development experience in Windows to the next level with WSL and Visual Studio Code Remote
- Part 2 An In Depth Tutorial on Linux Development on Windows with WSL and Visual Studio Code
- Part 3 Tips and Tricks for Linux development with WSL and Visual Studio Code
Here's the benefits of WSL 2
- Virtual machines are resource intensive and create a very disconnected experience.
- The original WSL was very connected, but had fairly poor performance compared to a VM.
- WSL 2 brings a hybrid approach with a lightweight VM, a completely connected experience, and high performance.
Again, now available on Windows 10 Insiders Slow.
Run multiple Linuxes in seconds, side by side
Here I'm running "wsl --list --all" and I have three Linuxes already on my system.
C:\Users\scott>wsl --list --all
Windows Subsystem for Linux Distributions:
Ubuntu-18.04 (Default)
Ubuntu-16.04
Pengwin
I can easily run them, and also assign a profile to each so they appear in my Windows Terminal dropdown.
Run an X Windows Server under Windows using Pengwin
Pengwin is a custom WSL-specific Linux distro that's worth the money. You can get it at the Windows Store. Combine Pengwin with an X Server like X410 and you've got a very cool integrated system.
Easily move WSL Distros between Windows systems
Ana Betts points out this great technique where you can easily move your perfect WSL2 distro from one machine to n machines.
wsl --export MyDistro ./distro.tar
# put it somewhere, dropbox, onedrive, elsewhere
mkdir ~/AppData/Local/MyDistro
wsl --import MyDistro ~/AppData/Local/MyDistro ./distro.tar --version 2
That's it. Get your ideal Linux setup sync'ed on all your systems.
Use the Windows Git Credential Provider within WSL
All of these things culminate in this lovely blog post by Ana Betts where she integrates the Windows Git Credential Provider in WSL by making /usr/bin/git-credential-manager into a shell script that calls the Windows git creds manager. Genius. This would only be possible given this clean and tight integration.
Now, go out there, install WSL, Windows Terminal, and make yourself a shiny Linux Environment on Windows.
Sponsor: Like C#? We do too! That’s why we've developed a fast, smart, cross-platform .NET IDE which gives you even more coding power. Clever code analysis, rich code completion, instant search and navigation, an advanced debugger... With JetBrains Rider, everything you need is at your fingertips. Code C# at the speed of thought on Linux, Mac, or Windows. Try JetBrains Rider today!
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
wsl --set-version <Distro> <Version>
Use this command to convert a distro to use the WSL 2 architecture or use the WSL 1 architecture.
: the specific Linux distro (e.g. “Ubuntu”)
: 1 or 2 (for WSL 1 or 2)
"Set a distro to be backed by WSL 2 using the command line
In PowerShell run:
wsl --set-version <Distro> 2
and make sure to replace <Distro> with the actual name of your distro. (You can find these with the command:
wsl -l). You can change back to WSL 1 at anytime by running the same command as above but replacing the '2' with a '1'.
Additionally, if you want to make WSL 2 your default architecture you can do so with this command:
wsl --set-default-version 2
"
Installation Instructions for WSL 2
I ask this because one sound bite, early on, implied the linux kernal is baked into windows so why would docker need that VM?
Will there be Visual Studio extensions for SSH, WSL, and containers?
That is all great that it can be done with VS Code, but my main development is Visual Studio. For which I do deployment to Linux and Containers. Having Remote Development with WSL with Visual Studio would be great.
You can remove the Google+ icon / integration 😇
sea shell and gave it to my 4 year old daughter and said
"You can hear the ocean if you put this to your ear." She put the shell to her ear
and screamed. There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this is completely off topic but I had
to tell someone!
something else, Anyhow I am here now and would just
like to say many thanks for a tremendous post and a all round thrilling blog (I also love the theme/design), I don't have time to look over
it all at the minute but I have saved it and also included
your RSS feeds, so when I have time I will be back to
read a lot more, Please do keep up the awesome work.
he must be visit this site and be up to date everyday.
I have always disliked the idea because of the costs.
But he's tryiong none the less. I've been using WordPress on a number of websites for
about a year and am worried about switching to another platform.
I have heard fantastic things about blogengine.net.
Is there a way I can transfer all my wordpress posts
into it? Any help would be greatly appreciated!
is truly superb.
With liposuction, the surgeon restores the harmonious shape of the patient’s body.
Removing stubborn fat deposits can improve the cosmetic appearance of any
individual.
more attention. I'll probably be returning to see more,
thanks for the advice!
It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between user friendliness and appearance.
I must say you have done a awesome job with this. Additionally, the blog loads extremely quick for me on Safari.
Exceptional Blog!
You will earn all the stuff For example, So, As, I would say about toyota,
house, baks, rich stuff. reached a process to create
thatm quick Slottica Registration; Https://Slottica-Com.Com/Signup, makes to lead the game everywhere.
In advance advise to see a few sited to know. People could have rough
going, although its kindly. And piece of luck
or mind will help https://slottica-com.com/signup/
who are wishing for blogging.
It contains nice data.
to share my knowledge here with mates.
will absolutely obtain nice knowledge.
is really fruitful in favor of me, keep up posting these articles or reviews.
thought I might check things out. I like what I see so i am just following you.
Look forward to finding out about your web page yet again.
you're talking about! Thanks
people, who are wishing in favor of blogging.
complicated to write.
I am confident they'll be benefited from this web site.
Comments are closed.
Some things though that I haven't been able to determine:
If the answer is no, can you "upgrade" from WSL1 to WSL2. Does that even make sense in the world of "WSL"?