Linux · Windows

Ubuntu Linux on Windows 10 how to


For the past year, Microsoft has been experimenting with the service known as WSL or Windows Subsystem for Linux. A setup that allowed you to run an Ubuntu terminal under Windows 10. These days since Windows 1709 (September 2017), WSL has come out of beta and is now available for general usage. This article will guide you through the steps to install, and setup Ubuntu 16.04 LTS on your Windows install.

Requirements

  • Windows 10 64-bit.
  • Windows 10 version 1709 or newer.
  • A familiarity with the Linux Bash shell.

To see your Windows version type in about in the taskbar search box (Cortana) and select About your PC.

About your PC example

Windows specifications example

If you’re using Windows 10 version 1703, the steps are different. I have previously covered the process here ‘Run Ubuntu 16.04 on Windows 10 Creators Update‘.

Install

By using the Microsoft Windows Store, we will install Ubuntu. These instructions will automatically launch the Store app and take you to the Ubuntu store page maintained by Canonical.

Copy and paste or open this link in the Microsoft Edge browser.
https://www.microsoft.com/store/productId/9NBLGGH4MSV6

Ubuntu in the Microsoft Store

Click the blue Get button to download the 200 MB Ubuntu package and install it without prompts.

Downloading .. Ubuntu

When finished click the Pin to Start to add Ubuntu to your start menu.

This product is installed.

Click the Launch to load Ubuntu and finalise the install.

Installing, this may take a few minutes...

When prompted give a new username and assign it a password. It will be your default Ubuntu account name and is unrelated to your Windows account login.

Enter new UNIX username: ben
Enter new UNIX password:
Retype new UNIX password:

Default UNIX user set to: ben
To run a command as administrator (user "root"), use "sudo <command></command>".
<command></command> See "man sudo_root" for details.


Congratulations you now have a working copy of Ubuntu 16.04 on Windows 10.

Try the following terminal commands in your Ubuntu prompt.

To see your Ubuntu version:
lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial

To see the Bash shell version:
bash --version

GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)

To see the Python version:
python3 -V

Python 3.5.2

Update

The Windows Store handles all updates to the Ubuntu app. But for programs within Ubuntu, a separate Linux package management and updates service named apt is used.

sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y

update refreshes the source links to the apt servers. upgrade downloads and installs program upgrades. autoremove cleans up any temporary downloads and out-of-date files.

Mirrors

If you find the updates are too slow, change the apt source links to point to a mirror that is geographically closer.

​​​​​​​​sudo nano -B /etc/apt/sources.list

Any links starting with deb http://archive.ubuntu.com/ubuntu/ may be changed.

As I am in Australia, I insert the AU country-code as a sub-domain of the links. For example:

deb http://archive.ubuntu.com/ubuntu xenial
becomes
deb http://au.archive.ubuntu.com/ubuntu xenial

Links beginning with deb http://security.ubuntu.com/ubuntu/ do not have mirrors so they cannot be modified.

Nano edit /etc/sources.list

Tap Ctrl-O to save your edits then Ctrl-X to exit Nano. Then apply the changes.

sudo apt update

Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:2 http://au.archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:3 http://au.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
...

Interacting with Windows files

Ubuntu can access both files stored in the Windows directory structure and even launch Windows programs. The subdirectories found within the /mnt directory represent your Windows drives.

ls /mnt

c

Directory c/ points to your Windows C: drive. This command will list the Windows program files directory.

ls '/mnt/c/Program Files/'

Don’t forget Ubuntu supports autocompletion for both file and directory names with the tap of the TAB ↹ key.

In this instance, we create some text. But we’ll save it as a file to a Windows 10 directory and then use Windows Notepad to view it, all within Ubuntu.

​​cd '/mnt/c/Users/Public/Downloads/'
echo 'Hello' > hi.txt
/mnt/c/Windows/System32/notepad.exe hi.txt

hi.txt viewed in Notepad

Close Notepad to regain use of Ubuntu.

I recommend using symlinks to connect your Windows User directory to your Ubuntu user account (called the home directory).

Go to your home directory and create a symlink.
cd ~
ln -sr /mnt/c/Users/Ben/Downloads ~/Downloads

Don’t forget to replace Ben in the path with your Windows user account directory name.

You can now list the content of your Downloads saved to your Windows account.
ls ~/Downloads

For documents.
ln -sr /mnt/c/Users/Ben/Documents ~/Documents
ls ~/Documents

Disable the terminal bell

One thing I find annoying is the Windows 10 terminal bell sound. As it’s often triggered after I tap the TAB ↹ key, but autocomplete has too many or no options. So I disable it.

sudo nano ~/.inputrc

Copy and paste in the following.

# ~/.inputrc - See http://ss64.com/bash/syntax-inputrc.html for more options
# do not bell on tab-completion
set bell-style none
# set bell-style visible

Save the text, exit Nano, then close the Ubuntu app. Re-launch it, and it should remain silent.

Run a simple web server

In Ubuntu, you can easily serve the current directory over the local web using Python. This command serves your home directory.

cd ~ && python3 -m http.server

In a web browser you can visit http://localhost:8000 and browse the home directory. To quit the Python Simple HTTP Server tap Ctrl+C a couple of times while in Ubuntu.

Serving HTTP on 0.0.0.0 port 8000 ...
127.0.0.1 - - [08/Nov/2017 18:10:48] "GET / HTTP/1.1" 200 -
^C
Keyboard interrupt received, exiting.

Create a Bash script

We will create a simple Bash script to run the apt update and upgrade processes.

Ubuntu has a few directories where you can create and store system-wide accessible scripts, but I keep them in /usr/local/bin.

cd /usr/local/bin
sudo nano upgrade.sh

Copy and paste the following script (source on GitHub).

#!/usr/bin/env bash
# /usr/local/bin/upgrade.sh
# Refreshes the APT repository applies any package upgrades.

sudo apt -y update
sudo apt -y upgrade
sudo apt -y dist-upgrade
sudo apt -y autoremove

Save then exit Nano and make the script executable.

sudo chmod +x upgrade.sh
sudo ln -s upgrade.sh upgrade

Now you can run the script from any location within the terminal, and those four apt commands should run in sequence.

cd ~
sudo upgrade

...
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Install a simple web server

It’s straightforward to install and run a dedicated web server in Ubuntu.

sudo apt -y install lighttpd
sudo service lighttpd status

* lighttpd is not running

sudo service lighttpd start

* Starting web server lighttpd

sudo service lighttpd status

* lighttpd is running

Type http://localhost/ into a web browser to view the Lighttpd Placeholder page.

The lighttpd Placeholder page

Lighttpd web content is stored in /var/www/

Its configuration file can be viewed.

nano /etc/lighttpd/lighttpd.conf

Its manual can be found at http://redmine.lighttpd.net/projects/lighttpd/wiki.

Note lighttpd will stop running when the Ubuntu app is closed.

To remove lighttpd.

sudo apt autoremove lighttpd

If you prefer, more popular web servers are available such as Apache HTTP and Nginx.

sudo apt install apache2
sudo apt install nginx

Compiling Linux source code

I use Nano as my go-to text editor, but the included version in Ubuntu is a bit out of date, so let’s update it. To do this, we can download, compile and install the most recent nano source code onto our Ubuntu environment.

nano -V

GNU nano, version 2.5.3
(C) 1999..2016 Free Software Foundation, Inc.

But first, we need to a one-time update our sources.list to allow apt access to the source code repositories.

sudo nano /etc/apt/sources.list

Append the following to the bottom of the file.

deb-src http://archive.ubuntu.com/ubuntu/ xenial main

You may include a country code mirror such as this case for the Australian mirror.

deb-src http://au.archive.ubuntu.com/ubuntu/ xenial main

Save and exit then update.

sudo apt update

Hit:1 http://au.archive.ubuntu.com/ubuntu xenial InRelease
...

Remove the default nano install.

sudo apt -y remove nano

Install the packages we need to compile our refreshed Nano application.

sudo apt -y build-dep nano
​s​udo apt -y install libmagic-dev

Download and extract the nano source code. You can check for the latest source code gzipped version at the nano editor site.

cd ~
​wget https://www.nano-editor.org/dist/v2.8/nano-2.8.7.tar.gz`

Resolving www.nano-editor.org (www.nano-editor.org)... 213.138.109.86
Connecting to www.nano-editor.org (www.nano-editor.org)|213.138.109.86
|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2822417 (2.7M) [application/x-tar]
Saving to: ‘nano-2.8.7.tar.gz’

tar -xf nano-2.8.7.tar.gz
cd nano-2.8.7

Now configure, compile the source code and then install the program.

./configure --enable-utf8

...
config.status: creating po/POTFILES
config.status: creating po/Makefile

make

...
Making all in syntax
make[2]: Entering directory '/home/ben/nano-2.8.7/syntax'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/ben/nano-2.8.7/syntax'
make[2]: Entering directory '/home/ben/nano-2.8.7'
make[2]: Leaving directory '/home/ben/nano-2.8.7'
make[1]: Leaving directory '/home/ben/nano-2.8.7'

sudo make install

Making install in doc
make[1]: Entering directory '/home/ben/nano-2.8.7/doc'
make install-recursive
make[2]: Entering directory '/home/ben/nano-2.8.7/doc'
...

​​source ~/.bashrc

nano -V

GNU nano, version 2.8.7
(C) 1999-2011, 2013-2017 Free Software Foundation, Inc.
(C) 2014-2017 the contributors to nano
Email: nano@nano-editor.org Web: https://nano-editor.org/
Compiled options: --enable-utf8

Brilliant you have just compiled GNU free software written for Linux on Windows 10.

Complete

That is it for this guide. You can also install the Windows 10 openSUSE app side-by-side with the Ubuntu app. I wrote a similar guide to this under openSUSE on Windows 10 how to.

More resources

Advertisements

3 thoughts on “Ubuntu Linux on Windows 10 how to

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s