Ubuntu Terminal on Windows
💻 Windows Subsystem for Linux (WSL) & VSCode
I change hardware devices more regularly than most, which has driven me to adopt technologies that run cross-platform in most instances (Codesandbox.io has a little more work before it’ll replace my local workflow). My OS of choice is Ubuntu; however, I find myself running Windows more often than I want. Thankfully, Microsoft has seen the light and offered a system on which Linux environments can run within Windows without VMs. This is my Windows environment setup:
Enable Windows Subsystem for Linux (WSL)
- Enable Developer Mode in Settings
- Search for “turn windows features on or off” and open Windows Features
- Enable Windows Subsystem for Linux & reboot
Install Ubuntu from Windows Store
- Ubuntu 16.04LTS or 18.04LTS
- Boot the app and follow the instructions to set up your user
- Update Ubuntu deps:
sudo apt-get update && sudo apt-get upgrade
Setup File System Syncing
The filesystem used by the Linux shell is hidden deep in your user’s AppData folder. To make developing more convenient we will set up a symlink between our projects
folder across the two environments:
- Create a
projects
folder in your Windows user space. I like to useC:\Users\james\projects
NB: Ubuntu will mount yourC:
drive to/mnt/c
- Open the Ubuntu app
- Create a symlink by linking your new
projects
folder from Windows to our Ubuntu userspace
ln -sv /mnt/c/Users/<windows username>/projects ~/projects
- validate the symlink with
ls -la
and creating, editing and deleting a file from each userspace to see that the changes are reflected correctly.
WSL with VSCode
It’s possible to set the integrated VSCode terminal to use Bash in place of Powershell. The App Store .exe for Ubuntu 18.04 seems to be inaccessible to the user via the filesystem, however, there is a bash.exe
app accessible via C:\Windows\System32\bash.exe
which appears to be the identical environment (if you have more details, please share so I can update this explanation).
Add these lines to your VSCode settings:
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe""terminal.external.windowsExec": "C:\\Windows\\System32\\wsl.exe"
Thanks to Bhramachari for pointing me to using wsl.exe
over bash.exe
as it will better support alternate terminals (ZSH, Fish etc).
If you set up the symlink as directed above you should be able to nav to
cd ~/projects/<your repo>/
and see the same files reflected.
Conclusion
Now you have Ubuntu and Bash you should be able to set up your Ubuntu developer workflow within Windows 💯
Take a look at my dev-tools setup here:
🚨 Caveat Emptor: There may be issues with running some Ubuntu tools within WSL as not all Ubuntu system calls are supported by WSL, however I have not come across this myself with any tool 👌
Need something else to read?
More by me:
📑 Table of Contents
An index post for my Medium Series
💻 Ubuntu 18.04 LTS on a Dell XPS 15
Stop Ubuntu from hanging itself on login
💻 Ubuntu 18.04 LTS on Lenovo ThinkPad E485
Stop Ubuntu from hanging itself on boot
If you found this useful, please recommend and share with your friends & colleagues