Running Ubuntu on Windows 10 with WSL2 — Part 2: Windows Terminal

Mauro Giusti
10 min readMay 8, 2020

--

Note: This is the second of a series of articles about running Ubuntu on Windows 10, check out the first chapter: Running Ubuntu on Windows 10 with WSL2 and Part 3: Visual Studio Code and go

After I shared how to run Ubuntu via WSL2 on Windows 10, let me now give you more details on the use and configuration of my favorite WSL2 terminal: the new Windows Terminal.

As I was trying WSL, I used multiple terminals for Windows: ConEmu, Hyper, cmder, the default WSL prompt, and the beta of the new Windows Terminal.

All the terminals listed above support WSL2: ConEmu and cmder were doing a pretty good job, but the select/copy/paster cycle was not working in every situation. Hyper was my least favorite, at the time of my tests: copy paste was not working, the prompt did not always respect my settings and history search was not there. Finally, the default WSL prompt is pretty basic and lacking configuration options.

I found that the Windows Terminal had everything I needed: it is lightweight, allows me to do select, copy and paste natually, supports command history and auto-complete without glitches, supports my favorite Powerline fonts and color themes, zsh and fzf.

Note that I don’t use tmux, if that is what you need, you can go with Nick Janetakis’ Tools I use article and try wsltty.

My code editor is Visual Studio Code, which I can use in remote mode with WSL, and I am fine with one terminal in a single window at a time with that (also Windows Terminal has tabs, which are good enough for me).

OK, now let’s see how I installed and configured Windows Terminal, so you can get the results above and be a happy Linux camper on Windows 10 + WSL2.

Installing Windows Terminal

Windows Terminal (Preview) is just an app in the Microsoft Store. It requires Windows 10 version 1903 (build 18362) or later, but, no worries: if you installed WSL2, you already have the right build (see my first article for the details if you haven’t yet).

To install, open the Windows Terminal web page on the Microsoft Store (simply https://aka.ms/windowsterminal) and select install/open.

This will open the Microsoft Store app on your PC, select Launch now and the Windows Terminal beta will install and open with the default shell (PowerShell):

To see what version you are on, click the menu down arrow and select about. At the time of writing, I am getting version 0.11.1121.0:

One of the great things about Windows Terminal is that it automatically updates itself on the background: I never had to run an install or update, I just find it updated with the latest version whenever I remember to check (which is right now because I am writing the article :D)

Setting Ubuntu as the default console

Ok, first thing, let’s set Ubuntu to be the default console on Windows Terminal. Select the Settings menu as in the picture below:

The settings are held in a json file and the editing will be manual, if you don’t have a code editor installed, select Notepad for now to edit it.

In the profiles list, look for the Ubuntu profile and copy its guid — mine is as follows:

{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl"
},

Then look for the defaultProfile property in your config file and replace it with the Ubuntu profile guid:

{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}", ...
}

(don’t worry if you mess up the json, Windows Terminal will warn you if it can’t load the profile as soon as you save it, so you can undo the changes)

Now if you close and reopen Windows Terminal, Ubuntu will be launched by default:

Personalizing the Ubuntu Shell

OK, on this topic you can really go crazy, there are tons of shells on Linux as well as personalizations. I like zsh because it is powerful yet very compatible with bash that we use on our servers. The amazing oh-my-zsh framework provides themes and plugins for zsh.

Here is how to get it installed on Ubuntu 18.04:

Install zsh

As easy as:

sudo apt update
sudo apt install zsh

Now set zsh to be your default shell:

chsh -s $(which zsh)

Open a new terminal and the initial zsh prompt will show up, signaling that zsh is now the default shell. At this point I suggest to pick 2 — it will populate the zsh configuration file ~/.zshrc with defaults.

If you have problems go to the zsh installation page here: https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH

Now you have the default zsh prompt.

Let’s check again that zsh is the default shell:

echo $SHELL
$SHELL --version

you should get the following results:

Install oh-my-zsh

Now we can install oh-my-zsh — as per instructions on https://ohmyz.sh/#install run:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

This is what you should see:

Notice that oh-my-zsh updated your ~/.bashrc file and made a backup of the old one.

Also notice that the prompt changed now, it is just your username.

OK, we are readty to customize oh-my-zsh next.

Changing Theme

We are going to make our color pretty and prompt useful. There are a lot of themes in oh-my-zsh, you can see them here: https://github.com/ohmyzsh/ohmyzsh/wiki/Themes

My favorite is agnoster:

To use it, you want to edit ~/.zshrc and set it as the selected theme.
I use nano as editor in Ubuntu (because of my Windows heritage), so here we go:

nano ~/.zshrc

The zsh theme is right on top of the file, change it to agnoster:

Save (ctrl+o) and exit (ctrl+x), now open a new shell and…

Let’s now change the color scheme and fonts, to make it match our iTerm2 configuration on the Mac.

Changing Color Scheme

Open the Windows Terminal Settings, using your json editor, find the Ubuntu profile, and add the color scheme line to use the color scheme you prefer (Solarized Dark in my case):

{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"colorScheme" : "Solarized Dark",
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl"
},

Save it and the color scheme is fixed:

If you want to see all the Windows Terminal options and all the available themes, you can press the Alt key while selecting Settings, and all the default settings will be present in the json.

There you can see all the available color schemes and how to add a new one. For more info, see Windows Terminal docs here: https://github.com/microsoft/terminal/blob/master/doc/user-docs/index.md

Installing Powerline fonts

Now we have to fix those weird characters in the prompt. In order to do so, we need to install the Powerline fonts and change the terminal theme.

Installng Powerline fonts in Windows is a bit involved, but there is a great Medium article on it: https://medium.com/@slmeng/how-to-install-powerline-fonts-in-windows-b2eedecace58

You can see the detailed steps there, but here is a summary:

  1. Go to the Powerline Fonts Github page.
  2. Click on the green “Clone or download” button and click “Download ZIP”
  3. You will get a fonts-master.zip file in your Downloads folder, unzip it there and open the folder with File Explorer.
  4. Right click on the install.ps1 file in the fonts-master folder and select Run with PowerShell:

5. At the PowerShell prompt for Execution Policy Change, say Y:

This will start the process of installing all the fonts in the download to Windows, this will take a couple of minutes to complete:

Now you have the Powerline fonts installed, edit the Windows Terminal json configuration file again, and add the Powerline font you prefer with the fontFace property. I like the Source Code Pro, so here it is:

{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"colorScheme" : "Solarized Dark",
"fontFace" : "Source Code Pro for Powerline",
"fontSize" : 12,
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl"
},

Note that you can also change the font size, the default is 12, I left it there for your reference.

And there we go, theme, font and colors schema set!

Finishing console touches

Ok there are a few finishing touches here, first, I don’t like seeing the user@machinenamein the prompt every time, this is ok when I ssh into a server, but on my local machine, this is just taking real estate off the prompt.

The solution on how to remove it comes from this response in Stackoverflow: this is a feature of the agnoster theme, to fix it, you just need to add:

export DEFAULT_USER="$(whoami)"

anywhere in your ~/.zshrc file:

now save, and open a new shell :

Great!

Now, we do not like at all that our Ubuntu home directory to be the Windows file system home directory of our users, we are in Ubuntu, and we want to start in our Linux home directory: ~ , don’t we.

Ok, for this just edit your Windows Terminal configuration again, the home folder is selected by the wsl command, used by the Windows Terminal, we can add a new line in the configuration to customize this:

{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"commandline" : "wsl.exe ~ -d Ubuntu-18.04",
"colorScheme" : "Solarized Dark",
"fontFace" : "Source Code Pro for Powerline",
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl"
},

Note that your wsl installation name could be different, so you could use this simpler option which will launch the default WSL distro:

  "commandline" : "wsl.exe ~",

Save, open a new terminal and…

Perfetto!

Now our terminal is ready, prompt, colors, theme, home directory are all set.

Last Ubuntu touches: fzf and completions

A couple more utilities to the Ubuntu shell will improve the overall experience.

I can’t live without fuzzy finder fzf, my bash history is my knowledge and searching with fzf is a breeze.

To install fzf on Ubuntu 18.10 you can download it using git:

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

When you are done, open a new shell instance and press crtl+r you can easily search your history now:

One of the best features of oh-my-zsh is support for lots of completions: when in doubt press tab and the list of possible commmands is listed for you to select.

To add completions support for docker or git just edit your ~/.zshrc file and edit the plugins line:

plugins=(git docker)

Find more information on docker completion in the docker web site.

The zsh-completions collection that includes tons of completions helpers for go and other linux utilities, can be installed with zsh by downloading it in the zsh custom plugins:

git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions

And adding it to the plugins in ~/.zshrc :

plugins=(git docker zsh-completions)
autoload -U compinit && compinit

Finally, to add completions for kubectl, you can add this to your ~/.zshrc file:

source <(kubectl completion zsh)

So now if you open a new shell and type go and press <tab> you will see the list of possible go commands:

All done, for now

Now you have an amazing shell for your Ubuntu installation on Windows 10 / WSL2, but this is not the end of the series. In Part 3: Visual Studio Code and go, we will see how to install and configure Visual Studio Code with WSL Remote as our development environment.

Until next time.

Ciao!

--

--