The Ubuntu Sub System (New Bash Shell) in Windows 10


Windows 10 has recently added a Bash Shell support. It is not just a simple shell. It contains a complete Linux subsystem, which means you can run Linux native code directly on Windows.

The Ubuntu Sub System (New Bash Shell) in Windows 10 is a truly Linux kernel (unlike cygwin, which is just a shell). It means that you can compile on Windows in the Sub System to Linux COFF binary file which also works if you copy that to the Linux system. It works vice versa.

I am developing some scripts and bots using Python3, and I found it simpler and convenient to use this Ubuntu Sub System on Windows 10. I am a Windows OS user and a casual Linux fan, and this works best for me.

It is more than enough if you want to develop some scripts (Python, BASH etc) for Linux. So you have the best of both worlds, while you still can enjoy Windows for the gaming, legacy software, Windows Batch CMD and if you are a geek, you still can write and run your scripts quickly e.g. awk, sed …

On the New Bash Shell, your windows Disk structure is mounted at /mnt/c, /mnt/d … so yes, it is a real sub-system instead of a emulator.

How to Enable Bash Shell on Windows 10?

Click the start and type in “Turn Windows Features on/off” and hit return. Alternatively, you can go to Control Panel and navigate to Programs, Turn Windows Features On/Off. Both methods should give you this dialog.

turn-windows-subsystem-for-linux-beta The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

Enable Ubuntu at Windows 10 via Turn Windows Feature On/Off

Scroll down and tick “Turn Linux Subsystem (Beta)”. It takes a few minutes before the Linux shell is made ready. You probably need to restart your PC before changes are taken into effect. On the first time, open the command line shell as administrator and type in lxrun /install to install the ubuntu sub shell (download the binaries/images from the Microsoft Store)

install-bash-on-windows-10 The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

install-bash-on-windows-10

How to Disable/Remove Bash Shell on Windows 10?

If you decide to remove the Linux Shell on Windows, here is how you should type in the following command in the Windows Cmd Prompt:

lxrun /uninstall /full

How to Change Default User on Bash Shell Windows?

At the very first time after setup, you are prompted a default user and set the password. You could change this later so that every time you open the bash shell, the default user is logged in.

lxrun /setdefaultuser root

The above command sets root account by default.

How to Install Software on Bash Shell Windows?

The answer is apt-get package manager. Basically the user experience is almost exactly the same as on the true Ubuntu OS. Let’s see below screenshot that I run the sudo apt-get install g++ to install the g++ compiler on the Linux Sub System.

apt-get-install-on-windows The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

apt-get-install-on-windows

These commands are also working exactly as expected:

1
2
3
4
apt-get update
apt-get autoremove
apt-get upgrade
apt-get dist-upgrade
apt-get update
apt-get autoremove
apt-get upgrade
apt-get dist-upgrade

It is more than a Shell

The most frequently daily Linux commands are supported quite well on this Linux sub system.

bash-on-windows-some-command The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

bash-on-windows-some-command

The Vim Editor seems working well.

bash-vim-editor The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

bash-vim-editor

htop (sudo apt-get install htop) to show my power HPZ800 server.

htop-on-bash-shell-windows The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

htop-on-bash-shell-windows

File/Directory Structure

The Bash Shell on Windows 10 has exactly the Linux File/Directory Structures e.g. /, /root, /home, the one root tree-like structure where everything is basically a file and can be mounted/dismounted.

bash-shell-directory-structure The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

bash-shell-directory-structure

The files in Windows C drive can be accessed at /mnt/c/ and the files in Windows D drive can be accessed at /mnt/d/ etc… Don’t worry, these are already set up for you so basically you don’t need to worry about configuring it.

No GUI/Graphic Applications yet

Unfortunately, only the console applications are supported in this shell, that means that you can’t start e.g. xstart GUI or playing a 3D game.

LSB Modules

If you type lsb_release -a, which will give you the version information:

1
2
3
4
5
6
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty

What is this Bash Shell for?

Bash Shell is not going to replace the Traditional CMD Shell. Neither the Bash Script is going to replace the Windows Batch or PowerShell. Bash Shell on Windows provides a handy tool for Linux lovers while they have to use Windows e.g. for Work.

Admit it or not, Linux shell is very powerful and basically it has no rivals when it comes to data processing, multitasking, programming, and so many more. Linux Bash Shell is not just a shell, but a entire complete programming language/environment.

Where there is a shell, there is a way! Click To Tweet
bash-shellshock The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

bash-shellshock

For example, in my case, I recently am developing a Linux 64-bit server application. The tool I am using is RAD Delphi. Instead of using a real Ubuntu server for debugging and deploying, I can just use this Bash Shell on Windows, which is a local server. The code compiled from Delphi RAD is a truly 64-bit Linux native code, which can be executed directly in this sub system on Windows.

Copy and Paste Not Well Supported

Unfortunately, you can’t copy (Ctrl + C) any text outside the shell and paste it (Ctrl + V or mouse right click) to the Bash Shell yet. It is not supported yet or it is a bug that is not fixed yet.

You may also like: 在Windows下最佳的Linux开发环境

First time, at Windows Command Prompt (CMD), type in BASH to launch the subsystem, you will be asked to choose your favoriate Linux Distro at Windows Store:

# bash
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

At windows store: You’ll be able to select different distro of Linux Sub System on the latest Windows 10: Ubuntu, Kali Linux, Debian, Alpine WSL, SUSE Linux, Open SUSE.

run-linux-on-windows-1024x607 The Ubuntu Sub System (New Bash Shell) in Windows 10 BASH Shell batch script linux linux shell technology news windows windows command shell Windows Subsystem for Linux

run-linux-on-windows

How to Verify that WSL is installed? (and Check Version of WSL version)

After Installation, you can verify the versions and Linux distribution by running the following command in the MSDOS prompt.

1
2
3
4
C:\> wsl -l -v
 
  NAME            STATE           VERSION
* Ubuntu-22.04    Running         2
C:\> wsl -l -v

  NAME            STATE           VERSION
* Ubuntu-22.04    Running         2

WSL2 Version is so much better than WSL, so go for it! Love Microsoft for Embracing the Open-source and Improve the Productivity!

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
1674 words
Last Post: How to Use the Dynamic Link Library in C++ Linux (gcc compiler)?
Next Post: Model-View-Controller Explained in C++

The Permanent URL is: The Ubuntu Sub System (New Bash Shell) in Windows 10

2 Comments

  1. Dom

Leave a Reply to ACMer Cancel reply