Disclaimer: MashTips is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission at no extra cost to you.

Home Guide How to Use Linux Bash Shell on Windows 10 and Run Linux...

How to Use Linux Bash Shell on Windows 10 and Run Linux Commands Without VirtualBox

Windows is the Most Popular Operating System for Desktops and Laptops. Whereas, Linux is loved by developers and professionals. You would have run Linux OS distros inside windows using a Virtual Machine. With Windows 10, you have an additional feature to run Linux on Windows without actually having a Virtual Machine. Since there is no Virtual Machine instance, no system overload.

Here, we will talk about WSL (Windows Subsystem for Linux) to get Linux Bash shell on Windows and run Linux commands without installing a Virtual Machine.

Content

  1. What is WSL (Windows Subsystem for Linux)
  2. Setting up WSL on Windows 10
  3. Upgrade to WSL 2
  4. Install Ubuntu on Windows 10 without Virtual Machine
  5. Enable GUI for Windows Subsystem for Linux
  6. Access Linux Desktop with Remote Desktop Connection
  7. Open Linux Terminal Anywhere
  8. Shared Folders for Windows & Linux
  9. Wrapping Up: Linux on Windows 10

What is WSL (Windows Subsystem for Linux)

The WSL or Windows Subsystem for Linux feature enables running Linux command-line tools and utilities on top of Windows. Using WSL, you can install your favorite Linux distro under the hoods of Windows. Also, these distros will include most CLI (Command Line Interface) tools, utilities, and applications.

The most interesting part is that everything in Linux will run without any modifications. Let’s see what all things you can do with this Linux Terminal on Windows:

  • Choose and install your favorite Linux Distro from Microsoft Store.
  • Run the most common Command Line tools such as grep, sed, and other ELF-64 binaries.
  • Bash shell script support.
  • Run different services such as Apache, PostgreSQL, etc.
  • Install extra tools with Linux default package manager.
  • Invoke Windows apps from a Unix-like shell.
  • Run Linux Workflows inside Windows.
  • Develop Linux Applications using the power of Windows tools
  • Manage IT infrastructure by running a cloud server distro inside Windows.

Related: 14 Best Portable Linux Distro to Boot and Run from USB

Setting up WSL on Windows 10

To set up a WSL or Windows Subsystem for Linux, we need to tweak Windows a little bit. We have to enable WSL Feature in Windows first:

  1. Click on Start, and Search and open “Turn Windows Features on or off“.
  2. In the popped up window, Find and enable “Windows Subsystem for Linux“.
  3. Click “OK.
  4. Once the changes are applied, save your works and click on “Restart.”

Or you can use Powershell to enable the feature. Run the following command in the PowerShell (Admin) and restart the computer when Prompted.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

After completing the new feature update, your PC will be ready to run Linux on Windows. Now let’s see how to install your favorite Linux Distribution in Windows with WSL.

Related: 10 Best Lightweight Linux Distros to Revive Old Computer (2019)

Upgrade to WSL 2

To switch your version of WSL to WSL 2, you have to tweak Windows with some Powershell commands. Let’s see how.

We can upgrade the version of a specific WSL Distro or the whole Distros at once. Now, Open Powershell as Administrator, by following the method mentioned above. Run the following commands in Powershell Window.

As the first step, Download WSL2 Kernel Update from Given Link.

https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

Install the setup as same as u do for other apps. Then proceed with the following.

For Specific Linux on Windows

To list out installed Linux distributions. If you don’t have any yet, follow the next section.

wsl --list --verbose

To set version to WSL 2:

wsl --set-version <distribution name> <version>

Example:

wsl --set-version Ubuntu-20.04 2
upgrade-wsl-two-for-ubuntu

For Global WSL for Windows

To enable WSL 2 as the global default, we have to enable one more additional feature in Windows Features.

  1. Open the Windows Features window.
  2. Check the checkbox near the feature called “Virtual Machine Platform“.
  3. Click on OK. enable-virtual-machine-platform
  4. Wait for the changes to apply.
  5. Restart your computer when prompted.

After restarting, open Powershell as Administrator and run the following command. Then restart your computer to update the feature from WSL 1 to WSL 2.

wsl --set-default-version 2
Set WSL 2 as the default global version

Here it is. Now proceed with installing your favorite Linux Distro in Windows.

Install Ubuntu on Windows 10 without Virtual Machine

WSL supports various Linux distributions. You can install any of the Linux distros listed below:

  • Ubuntu LTS(Base)
  • Ubuntu 20.04 LTS
  • Kali Linux
  • Debian
  • OpenSUSE Leap
  • SUSE Linux Enterprise Server

Here, we are going to install Ubuntu 20.04 LTS. You can choose any distro of your choice.

search wsl microsoft store

  1. Open Microsoft Store.
  2. Search for “WSL” in the search box in the top right corner.
  3. Click on “Ubuntu 20.04 LTS“, or any other distro listed above.
  4. Click on Get > Install.
  5. Wait until the install finish.

install-ubuntu-20-04-lts

Now that Ubuntu 20.04 LTS is ready for the first launch. You can either click on the launch button in Microsoft Store or launch from the Start Menu.

The first setup will take some time for registering the Ubuntu environment with WSL. Once that’s finished, the prompt will ask for the Username and Password for your Linux Shell. Enter and complete setup.

After, you can try your favorite Linux commands in this Ubuntu Shell. By default, the home directory of this Windows 10 Linux will be clean and tidy. Hence it gives all the freedom to the user for customizations.

Run the following commands in Ubuntu Terminal to check if the system is up to date.

sudo apt update
sudo apt dist-upgrade

The “update” command is used to update the Ubuntu repositories. And the “dist-upgrade” command upgrade packages with all their dependencies. Wait for them to complete.

Now you can install any tools and apps of your need in this Ubuntu Environment.

Related: How to Share Clipboard Data Between Android and Ubuntu (Linux)

Enable GUI for Windows Subsystem for Linux

We can run Linux GUI apps in our Windows Environment itself. To enable GUI on Windows 10 Linux Terminal needs to install some tools in both environments. For the time being, we have to use thirty party apps to run the GUI apps in Windows 10 Linux Terminal.

Installing the X Server Utility

X Server provides almost everything needed to interact with the Linux WSL on Windows. This includes all graphical resources and keyboard/mouse events. The best option available for now is the VcXsrv Windows X Server.

  1. Download and install the VcXsrv from the link given below. https://sourceforge.net/projects/vcxsrv/
  2. Run the setup, and choose “Full” in the selection box to install the complete X Server Utility.vcxsrv install setup
  3. Once install finishes, launch XLaunch from Start Menu.
  4. This will lead you to a couple of configurations.
  5. On the “Display Settings” window, choose “One Large Window” or “One Window without title bar”. Leave Display number as “-1”. Click Next.xlaunch display settings
  6. In the next window, choose “Start no client” and click on Next.xlaunch client startup settings
  7. On the “Extra Settings” window, check the “Disable access control” option. This will avoid the “Permission Denied” errors while running GUI apps.xlaunch extra settings
  8. To avoid running into errors later, save the configuration from the next window. Also, always ensure you are running the X Server with this saved configuration.
  9. Click on Finish. A Security alert will follow up. Make sure both Private and Public are checked. And Click on Allow Access.xlaunch enable network access control
  10. Close the black window opened up for now. Because we got to do a little more on the Linux side also.

Configure Display Manager in Linux

Now we have to enable Linux to communicate with X Server utility, and of course, this happens over the local network.

Simply copy and paste the following command in the Linux Terminal for Windows and press Enter.

For WSL 1:

export DISPLAY=:0
export LIBGL_ALWAYS_INDIRECT=1

For WSL 2:

export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0"
export LIBGL_ALWAYS_INDIRECT=1

This is to set the Display environment of Linux to use the IP address of Windows Host as both WSL and Windows are not in the same network device.

Then enter the following to check whether your host IP is changed or not.

echo $DISPLAY

This step is very important so that the WSL can communicate with X Server on each launch. To run this command on each startup of Linux Terminal, you can include it to /etc/bash.bashrc file. Follow the steps below:

Run the following to open the file with Nano editor in the Linux Terminal with Superuser privileges. Enter your password when prompted.

sudo nano /etc/bash.bashrc

Add the following to the end of the file. Use the Down Arrow key to navigate the cursor. After copying the code, right-click on the mouse button to paste it inside the Terminal Window.

For WSL 1:

export DISPLAY=:0
export LIBGL_ALWAYS_INDIRECT=1

For WSL 2:

export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0"
export LIBGL_ALWAYS_INDIRECT=1

Then press Ctrl + X to exit. The prompt will ask you to save the buffer. Press the Y key. And then press Enter key. From now, each time you open the Linux Terminal on Windows, the Display Host IP is set to Windows Host IP.

export-variable-to-bash-file

Installing a Linux GUI app

To ensure everything is working, let’s install and test a Linux GUI app inside the Ubuntu WSL terminal. For Demo, I am using Gedit Text Editor. You can use any one of your choices.

To install Gedit, follow the commands below:

sudo apt install gedit

This will install all xserver utilities needed for the GUI app to run inside the Native Linux Environment along with Gedit. Press Y when the prompt asks for confirmation.

After finishing the installation, find the saved XServer configuration. Double Click on the file to start the X Server with a saved configuration. Make sure the X Server’s Blank Window is running in the background. Then switch to the Linux Terminal, and start the Gedit by running the following command:

 gedit

The Gedit GUI will be opened in the X Server Window. You can now do whatever you do with a native Linux GUI App. Always make sure XLaunch is running before you launch any GUI Apps on Windows Desktop Environment.

That’s all about Enabling GUI on Linux Terminal for Windows. Now, there is another way to interact with WSL distros with RDP(Remote Desktop Protocol) Connection. Let’s have a look into it.

Related: 10 Best Linux Games to Play In 2021

Access Linux Desktop with Remote Desktop Connection

Since Linux supports RDP, we can also connect to Linux Desktop through Remote Desktop Clients. For this, we need to install a Linux Desktop environment in the Linux On Windows first. I am going ahead with xfce4 since it is one lightweight Linux environment.

Enter the command:

sudo apt install xfce4

The setup will ask you to choose a display manager for Linux. Choose gdm3 or lightdm. And Press Enter.

Also, we need to initialize a graphical login interface for the RDP connection from Microsoft Remote Desktop. For this, install and start a service called xrdp in the Linux Terminal.

For Ubuntu:

sudo apt install xrdp
sudo service xrdp start

The start command will ask for network access. Click Allow access to accept.

To check whether it is running, perform the following command:

service xrdp status

Then we have to find out the IP address of the Ubuntu Machine. For that, run:

ip a

Copy the IP address of your adapter which supports “MULTICAST, BROADCAST”. Use Ctrl + Shift + C to copy from the Linux Terminal for Windows.

  1. Then click on the Start menu on Windows, and type “mstsc”.
  2. Paste the copied IP address in the “Computer” field.
    remote desktop client ip
  3. Click on Connect. Then, click Yes on the next prompt. You will be redirected to the Xrdp login.accept remote desktop connection
  4. Enter your Linux username and password and click Ok. xrdp login to linux

If this fails with a message shown below, check out the method following.

Your computer could not connect to another console session on the remote computer because you already have a console session in progress.

Let’s configure Xrdp a little bit. Run the following commands in sequence.

sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
sudo service xrdp restart

Then, again try to connect to Linux on Windows with Microsoft Remote Desktop Client as described above.

There you go. A complete Linux Desktop Environment under Windows Desktop.

Open Linux Terminal Anywhere

To open up Linux Terminal anywhere on Windows:

  1. Press Shift + Right Click on the plain area of any folder.
  2. Click on Open Linux shell here.open linux shell here
  3. The Linux Terminal will open for the Folder you are currently in.

Related: Get Hyper Terminal on Windows 7 and 8

Shared Folders for Windows & Linux

The WSL folders and files are stored in Windows as Shared Network Drives. We are going to access those files through some simple steps. Tweaking the “Shared Folder” with Linux on Windows:

  1. Click on Start Menu.
  2. Type in \\wsl$ and press Enter.wsl shared network drive
  3. A network drive will be shown with the name of your Installed Version of Linux.select linux distro drive
  4. Open the folder and you will find the Linux root folder and files.
  5. Now you can manage WSL files and folders right from Windows.

Wrapping Up: Linux on Windows 10

WSL provides a lot of handy features to a normal Windows user to taste the flavors of Linux. This feature can help you do more with your needs. This enables a lot of Linux-only features inside Windows. WSL is the perfect choice for you if you want to run Linux on Windows 10 without making an overload for your computer.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Free Newsletter

Related Articles