Installation of WSL on Windows 10 Pro

<!-- markdownlint-disable MD014 -->


# Setting of WSL


This article was written in 2019-03-09.


Please note that version of Windows, WSL, and other installed applications on Ubuntu may differ when you are reading this article; there is no guarantee to success those installation.


## Install Ubuntu 18.04 from Windows Store


Install Ubuntu 18.04 by GUI. Google it for instructions.


## Windows settings


Install VcXsrv from [https://sourceforge.net/projects/vcxsrv/](https://sourceforge.net/projects/vcxsrv/)
[see installation process](https://www.atmarkit.co.jp/ait/articles/1812/06/news040.html)


## bash on Ubuntu


start bash by clicking Windows' start menu -> Ubuntu 18.04. Then,


```sh
$ sudo apt update && sudo apt upgrade -y
```


### X11


```sh
$ cat << EOF >> .bashrc
export DISPLAY=localhost:0.0
export LIBGL_ALWAYS_INDIRECT=1
EOF

# check
$ source .bashrc # need reload
$ sudo apt install x11-apps
# check launch
$ xeyes
```


Then install other x11s


```sh
$ sudo apt install x11-utils x11-xserver-utils dbus-x11
```


### Language

Set Japanese.

```sh
$ sudo apt install language-pack-ja
$ sudo update-locale LANG=ja_JP.UTF-8
# check
$ echo $LANG
$ locale
```


### Timezone


```sh
# selected Asia/Tokyo
$ sudo dpkg-reconfigure tzdata
```


### Japanese input on Xapp


I tried to install ibus-mozc, but it didn't work. So decided to use uim-anthy. See fcitx-mozc installation at https://qiita.com/maromaro3721/items/be8ce6e3cec4cbcdac00


reference: https://tobubiyori.blogspot.com/2017/04/creaters-update-ubuntu-1604bash-on.html


#### uim-anthy


```sh
$ sudo apt install leafpad uim uim-xim uim-anthy
# font for x11
# $ sudo apt install fonts-ipafont
$ sudo apt install fonts-noto-cjk fonts-noto-color-emoji
# check Ctrl-Space or 半角/全角 ボタン
$ echo << EOF >> .bashrc
# for uim input
export XIM=uim
export XMODIFIERS=@im=uim
export UIM_CANDWIN_PROG=uim-candwin-gtk
# export UIM_CANDWIN_PROG=uim-candwin-qt
export GTK_IM_MODULE=uim
export QT_IM_MODULE=uim
#
if [ $SHLVL -eq 1 ]; then
          uim-xim &
fi
EOF

# for Japanese keyboard
$ echo << EOF >> .uim
(define default-im-name 'anthy)
(define-key generic-on-key? '("Henkan_Mode" "zenkaku-hankaku" "<Control> " "<Control>\\"))
(define-key generic-off-key? '("Muhenkan" "zenkaku-hankaku" "<Control> " "<Control>\\"))
(define-key anthy-extend-segment-key? '("<Control>o"))
(define-key anthy-shrink-segment-key? '("<Control>i"))
EOF

$ source .bashrc
$ leafpad
```


### Desktop -> LXDE


```sh
$ sudo apt install lxde
$ startlxde
```


or


```sh
$ sudo apt install lxpanel
$ lxpanel --profile LXDE &
```


Change default directory names from Japanese to English like デスクトップ -> desktop


```sh
sudo apt install xdg-user-dirs-gtk
LANG=C xdg-user-dirs-gtk-update
```


## Intellij


Note: `snap` command is not working on WSL now.


```text
Interacting with snapd is not yet supported on Windows Subsystem for Linux.
This command has been left available for documentation purposes only.
```


Unofficial Debian / Ubuntu packages of IntelliJ IDEA from JetBrains.
https://launchpad.net/~mmk2410/+archive/ubuntu/intellij-idea
*Note: It is your responsibility to use unofficial installer*


```sh
sudo add-apt-repository ppa:mmk2410/intellij-idea
sudo apt update
sudo apt install intellij-idea-community
```


IDE -> プログラミング -> IntelliJ IDEA Community Edition
(/usr/share/applications/intellij-idea-community.desktop)


## docker on WSL


Note: Ubuntu 18.04 on WSL with **Windows 10 1803 does not support latest docker of version 18**.
You need to update windows 10 from 1803 to **1809**.
(https://www.microsoft.com/ja-jp/software-download/windows10)


reference: http://j-levia.hatenablog.jp/entry/2019/01/02/234032


```
$ uname -a
Linux *** 4.4.0-17763-Microsoft #253-Microsoft Mon Dec 31 17:49:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"
```


**The below operation is bad installation, showing only for demostrate purpose**


```sh
# install (fails)
sudo apt update && sudo apt upgrade
sudo apt install -y docker.io
sudo apt-get install -y docker.io
# restart bash as Admin priviledge (meaning cmd or other console runs as Admin and typo `bash`)
sudo usermod -aG docker $USER
sudo cgroupfs-mount
sudo service docker start
docker run hello-world
```


Error occurs. Need to downgrade (see https://github.com/docker/for-linux/issues/591)


```sh
$ docker run hello-world
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:301: running exec setns process for init caused \"exit status 23\"": unknown.
ERRO[0009] error waiting for container: context canceled
```


Install docker-ce, not docker.io
(https://www.quora.com/What-is-the-difference-between-docker-engine-and-docker-io-packages)


```sh
# https://docs.docker.com/install/linux/docker-ce/ubuntu/
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs)  stable"
# check previous version
apt-cache madison docker-ce
sudo apt-get install docker-ce=18.06.1~ce~3-0~ubuntu # this version works

# service
sudo usermod -aG docker $USER

sudo cgroupfs-mount
sudo service docker start
docker version
```


If docker service is resistered, you do not need run bash as Admin.
Restart your windows shell as normal user.


```sh
$ docker run -it --rm hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
```

That's all.