The easy way to get Ubuntu 18.04 distro environment on Windows

3 minute read

Remember my previous Getting Ubuntu distro environment on Windows for DevOps blog post where I demonstrated on how to obtain Ubuntu 16.04 on Windows 10 or Windows Server and perform an in-place upgrade to Ubuntu 18.04?

Guess if you are a 100% pure Windows user and performing an in-place upgrade to Ubuntu 18.04 in bash is not something you are comfortable with, you can start uninstalling the Ubuntu 16.04 and install Ubuntu 18.04 again.

In this blog post, I will be providing a guide on how you can quickly get the Ubuntu 16.04 replaced by Ubuntu 18.04 on your Windows. Let’s get started with the upgrade in command lines.

A quick guide in getting Ubuntu 18.04 on Windows

This is a quick walk-through guide in removing Ubuntu 16.04 from Windows Subsystem for Linux in Windows and install Ubuntu 18.04 onto Windows Subsystem for Linux in Windows to refresh the Ubuntu distro environment to keep it up to date.


Top


Uninstalling a Windows Subsystem for Linux distribution

To uninstall Ubuntu 16.04 from Windows Subsystem for Linux, use the lxrun command with the /uninstall and /full parameters.

Note: For Ubuntu 16.04 from Windows 10 Store, you can right click on the app tile and select Uninstall.

1
lxrun /uninstall /full

Top


Ensuring Windows Subsystem for Linux feature is enabled

This section is to validate that Windows Subsystem for Linux feature is enabled on Windows 10 or Windows Server and automatically enabling the feature if it is found to be not enabled.

Note: A reboot of the Windows operating system is required after enabling the Windows Subsystem for Linux feature.

1
2
3
4
5
6
7
8
9
10
11
12
# Check if Microsoft-Windows-Subsystem-Linux feature is enabled 
if((Get-WindowsOptionalFeature `
    -FeatureName "Microsoft-Windows-Subsystem-Linux" `
    -Online).State -ne "Enabled")
{
    # Enable Microsoft-Windows-Subsystem-Linux feature if
    #  the feature is not enabled
    Enable-WindowsOptionalFeature `
        -FeatureName "Microsoft-Windows-Subsystem-Linux" `
        -Online `
        -NoRestart:$False ;
}

Top


Downloading Ubuntu 18.04 distro instance

Once we have confirmed that requirement of Windows Subsystem for Linux feature is enabled, we can initiate a download of Ubuntu 18.04 application.

Note: You can rename the -OutFile "<long file name>" to -OutFile "~\Ubuntu1804.appx" instead of the long file name.

1
2
3
4
5
# Download Ubuntu application for WSL
Invoke-WebRequest `
    -Uri "https://aka.ms/wsl-ubuntu-1804" `
    -OutFile "~\CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2018.817.0_x64__79rhkp1fndgsc.appx" `
    -UseBasicParsing ;

Top


Installation for Windows 10

Natively, you can use Add-AppxPackage PowerShell cmdlet to add the linux distro application package to your Windows 10.

1
2
3
# Install the Ubuntu application for WSL
Add-AppxPackage `
    -Path "~\CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2018.817.0_x64__79rhkp1fndgsc.appx" ;

Top


Installation for Windows Server

For Windows Server, you will have use Rename-Item PowerShell cmdlet to rename the linux distro application package extension to a compressed file extension.

Since the file has been renamed to a compressed file extension, you will use Expand-Archive PowerShell cmdlet to expand the compressed file to your home folder or ~\.wsl\distro\ custom home folder location.

After the file has been expanded to the destination, use the Start-Process PowerShell cmdlet to launch the executable to begin the initial configuration of the linux distro instance.

1
2
3
4
5
6
7
8
9
10
11
12
13
# Rename the file extension to compressed file extension
Rename-Item `
    -Path "~\CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2018.817.0_x64__79rhkp1fndgsc.appx" `
    -NewName "Ubuntu1804.zip" ;

# Expand the compressed file to destination
Expand-Archive `
    -Path "~\Ubuntu1804.zip" `
    -DestinationPath "~\.wsl\distro\Ubuntu" ;

# Launch the distro setup
Start-Process `
    -FilePath "~\.wsl\distro\Ubuntu\Ubuntu1804.exe" ;

Top


Updating the Ubuntu 18.04 distro instance

Finally, you will have to switch into the Ubuntu 18.04 bash and perform an update of the packages to keep up to date.

1
2
# Update and upgrade Ubuntu
sudo apt update && sudo apt upgrade

Top


Conclusion

That’s all on how to obtain Ubuntu 18.04 on Windows Subsystem for Linux and stay up to date with Ubuntu releases for any Windows administrators out there that does not want to meddle with any Linux package manager.

If you find that this information useful, feel free to bookmark this or share it with your colleagues and friends.


Top


References


Top



Top