Installing Windows Subsystem for Linux (WSL) using PowerShell

Interestingly, Microsoft has decided to bridge the Windows platform with Linux and allows developer to be comfortable on Windows 10 with any command-line tools that they are familiar with. No more standing up a Linux virtual machine, a Linux container or SSH to a remote Linux machine with PuTTY to do some work.

Let us see this in action on Windows 10…

For Demo purposes, I will use the following PowerShell command to display my Windows 10 version.

# Display Demo Machine Information
Get-ComputerInfo | `
    Select-Object `
        @{N='Hostname';E={$env:COMPUTERNAME}}, `
        WindowsProductName, `
        WindowsCurrentVersion, `
        WindowsVersion, `
        WindowsBuildLabEx | `
            Format-Table `
                -AutoSize ;

Secondly, I will display the current Microsoft’s Windows Subsystem for Linux feature is not enabled yet.

# Validate if Linux Subsystem feature state has been enabled on Windows 10
Get-WindowsOptionalFeature `
    -FeatureName Microsoft-Windows-Subsystem-Linux `
    -Online ;

Once I confirmed that the Windows Subsystem for Linux (WSL) feature is not enabled, we shall demonstrate on enabling this feature on your Windows 10. Just take note that your Windows 10 will requires to reboot in order to complete the feature enablement.

# Enable the Microsoft Windows Subsystem Linux Feature on Windows 10
#  and reboot the Windows 10
Enable-WindowsOptionalFeature `
    -FeatureName Microsoft-Windows-Subsystem-Linux `
    -Online `
    -NoRestart:$False ;

After rebooting your Windows 10, use the Get-WindowsFeature cmdlet to validate the Windows Subsystem for Linux has been enabled.

# After enabling Linux Subsystem feature and rebooted the Windows 10,
#  validate if Linux Subsystem feature state has been enabled on Windows 10
Get-WindowsOptionalFeature `
    -FeatureName Microsoft-Windows-Subsystem-Linux `
    -Online ;

If you have Windows Subsystem for Linux feature enabled, you can try using Bash in Ubuntu distro using the command-line below.

# To immediately start using Bash from the current default Ubuntu distro
lxrun /install /y

When the installation has completed, you can use the “bash” command to enter the Bash environment from Command Prompt or PowerShell console.

# Now, let us try switching into Bash
bash

You can validate the Ubuntu version in Bash using the command below.

# Let us validate the version in Bash
lsb_release -a

As a rule of thumb for me, I will always want to obtain the latest Ubuntu version to work with and therefore you can use the command-line below to update and upgrade your Ubuntu version.

# Before doing anything in Bash, also ensure your Bahs is updated and upgraded
sudo apt-get update
sudo apt-get upgrade

Let’s try something different…

# Now that we are in Bash, let us 
#  try generating a screenfetch
sudo apt-get install lsb-release scrot
wget -O screenfetch 'https://raw.github.com/KittyKatt/screenFetch/master/screenfetch-dev'
chmod +x screenfetch
./screenfetch

If Bash environment from Ubuntu operating system is not your preferred Linux distro to work with, use the PowerShell command below to launch Windows Store and get your preferred Linux distro into your Windows 10.

# Now, Launch Windows Store and get your preferred Linux distro
Start-Process `
    -FilePath "ms-windows-store://collection/?CollectionId=LinuxDistros" ;

Conclusion
I find that having the best of both world in a single operating system in Windows 10 is what I really need and I cannot find any other OS having the same capability without either having to spin up a VM or Container. Beside happy PoSHing, we can now be Bashing too.

Reference

Advertisement