set up ubuntu bash and vscode on windows 10 for web development

set up ubuntu bash and vscode on windows 10 for web development

One windows 10 feature, the ability to run a native linux shell in windows, made me curious. I usually use ubuntu as working desktop, but sometimes I am on a windows desktop, doing some web development and wish to have a linux shell at my fingertips without rebooting or virtualboxing.

UPDATE: Your Windows VSCode Installation can use your Linux Subsystem shell too!

To make the transition from windows to linux easy, you can open your windows store and search for "Linux" and go along with the first proposal:

install-a-linux-subsystem-on-windows-1-1
(All screenshots are taken from a windows 10 virtualbox, provided by modern.ie and are copyrighted by microsoft)

install-a-linux-subsystem-on-windows-2-2

I clicked on Ubuntu and found this setup hint:

To use this feature, one first needs to use "Turn Windows features on or off" and select "Windows Subsystem for Linux", click OK, reboot, and use this app.

So let's do this.

enable "Developer mode"

But first you need to switch your user account into developer mode otherwise you will not find any Windows Subsystem for Linux in the Turn Windows features on or off dialog.

To do this, click on the windows icon in your taskbar and select the settings cog:
windows-10-developer-settings-0

In the next window click in the input box, type developer in and select the first option:
windows-10-developer-settings-1

In the upcoming screen select the last option Developer mode:
windows-10-developer-settings-2

Accept the popup warning by clicking Yes:
windows-10-developer-settings-3

You are now able to enable the Windows Subsystem for Linux. :-)

enable feature "Windows Subsystem for Linux"

Open settings window again, use the find a setting input and type in features:
enable-windows-subsystem-for-linux-1

Click on Turn Windows features on or off and in the next popup scroll down until you find the Windows Subsystem for Linux:
enable-windows-subsystem-for-linux-2

Check the checkbox, click OK and after a short time windows wants to restart:
enable-windows-subsystem-for-linux-3

install a linux subsystem

After the reboot open the Microsoft Store and enter Linux into the searchbox:
install-a-linux-subsystem-on-windows-1

Select Run Linux on Windows and you find yourself in this screen:
install-a-linux-subsystem-on-windows-2

For this presentation I choose Ubuntu:
install-a-linux-subsystem-on-windows-3

Click on Get:
install-a-linux-subsystem-on-windows-4

And it is done... I clicked on Pin to Start and the Startmenu looks like this:
install-a-linux-subsystem-on-windows-5

first start

The first start of the subsystem takes a while:
first-run-windows-subsystem-for-linux-1-1

And then you need to setup your linux user:
first-run-windows-subsystem-for-linux-2

And you are running!

first steps

The windows filesystem is mounted under /mnt/c/ or any drive letter you have:
first-steps-1

Tools like vim, curl, wget, ssh, git, zsh, oh-my-zsh, nvm, yarn, composer are installable. Services like mysql, apache, node and docker are working.

When you install and start an apache webserver, edge browser will show a website by calling the url http://localhost/.
apache-on-ubuntu-on-windows-subsystem

Or, for example, if you build an EmberJS App and run it with the ember server command, your windows' browsers (edge, chrome, firefox) will show you the app on http://localhost:4200.

But your smartphone will not be able to open http://<your-windows-pc-ip>:4200 because windows' firewall will not allow this. But this is configurable, either you choose an open port in your app settings, or you allow this port in your windows firewall.

enable linux shell in your windows VSCode

I enjoy VSCode and you can configure your Windows VSCode installation to use the linux shell as well!

Start VSCode enter File -> Settings -> Settings and simple put the following line to your local VSCode configuration:

{
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\bash.exe"
}

VSCode-linux-subsystem

one more point

Right after the start, the linux subsytem is not available on windows. I do not know what happens, but it takes some time after your logon to windows, to access the shell.

If your VSCode tells you that no bash is available, just close and restart VSCode. This is a windows habit, not a VSCode habit.

Right after window statup, you will not find your ubuntu/debian/etc linux shell even in the startmenu. So don't panic ;-)

sum up

Coming from linux, I always miss the power of the command line on windows systems and cygwin or git bash do not make me happy. :-(

I enjoy this linux subsystem, even it is not as fast as a native linux installation. After setting it up, I can easily get a ssh client running, checkout a git project, use nvm and npm and all other tools I need for web development.

In combination with VSCode, you can start any modern frontend development from your Windows system. This is really great.

Article image from Casey Allen via unsplash and ghost.