Setup Ubuntu 18.04 on WSL on Windows 10 Pro

Table of Content

Install Ubuntu 18.04

Install Ubuntu 18.04 through Microsoft Store on Windows Subsystem for Linux (WSL) on Windows 10 Pro (ver. 1803). It is very simple.

Update and upgrade Ubuntu 18.04

Update and upgrade Ubuntu 18.04 as follows. It will take a long time.
[cc lang='bash']
username@HOSTNAME:~$ sudo apt update && sudo apt upgrade -y
[sudo] password for username:
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
... (Long lines continued)
[/cc]
You can check the version.
[cc lang='bash']
username@HOSTNAME:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04 LTS
Release: 18.04
Codename: bionic
[/cc]

Sharing Windows' folders

To make it easy to access the Windows' folder, create a link from the home directory to the Windows C drive. Windows C drive corresponds to [cci]/mnt/c[/cci] on Ubuntu. Suppose its directory name on Ubuntu is [cci]winc[/cci], append the following in [cci].bashrc[/cci] existing in the home directory. The statement of [cci]if[/cci] is to avoid duplicated link.
[cc lang='bash']
if [ -d winc ] ; then
echo "Windows shared folders ready"
else
ln -s /mnt/c winc
fi
[/cc]
To activate, use [cci]source[/cci] command.
[cc lang='bash']
username@HOSTNAME:~$ source .bashrc
[/cc]

Install packages and software

Preparing numerical computation environment for, e.g., FVCOM, install basic packages and software.

Install HDF5 and GMT-5

It is easy to install GMT-5 on Ubuntu 18.04 using apt.
[cc lang='bash']
username@HOSTNAME:~$ sudo apt install subversion git build-essential cmake libhdf5-dev
username@HOSTNAME:~$ sudo apt install libcurl4-gnutls-dev libnetcdf-dev libfftw3-dev libpcre3-dev
username@HOSTNAME:~$ sudo apt install liblapack-dev libblas-dev gfortran g++
username@HOSTNAME:~$ sudo apt install gmt gmt-dcw gmt-gshhg
[/cc]
[cci]netcdf.inc[/cci] is included in [cci]/usr/include/[/cci] and libraries are included in [cci]/usr/lib/x86-64-linux-gnu/[/cci].
To invoke GMT commands, use [cci]gmt[/cci] as follows:
[cc lang='bash']
username@HOSTNAME:~$ gmt psconvert test.ps -A -Tg -E600
[/cc]

Install Intel Parallel Studio XE 2018

[cci]Intel Parallel Studio XE 2018[/cci]は[cci] has not been compatible with Ubuntu 18.04[/cci], it seems possible to be installed. Official support for Ubuntu 18.04 will be done on [cci]Intel Parallel Studio XE 2019[/cci]. Following this article, you can install but I chose the custome installation and disabling [cci]IA-32[/cci] and the bottom two components, including GNU Debug. During the installation process, you will encounter an error of missing [cci]glibc libstdc++ libgcc[/cci], which should be ignored.

Install netcdf-fortran using Intel compiler

Referring to this article, I built netcdf4-fortran using Intel compiler.
Downloading [cci]netcdf-fortran-4.4.4.tar.gz[/cci] from this site in [cci]~/Downloads[/cci], unpack it and create [cci]config-intel.sh[/cci].
[cc lang='bash']
username@HOSTNAME:~/Downloads$ tar xf netcdf-fortran-4.4.4.tar.gz
username@HOSTNAME:~/Downloads$ cd netcdf-fortran-4.4.4
username@HOSTNAME:~/Downloads/netcdf-fortran-4.4.4$ vi config-intel.sh
[/cc]
Using vi editor, edit [cci]config-intel.sh[/cci] as follows:
[cc lang='bash']
export CDFROOT="/usr"
export LD_LIBRARY_PATH="${CDFROOT}/lib:${LD_LIBRARY_PATH}"
export LDFLAGS="-L${CDFROOT}/lib -I${CDFROOT}/include"
export OPTIM="-O3 -mcmodel=large -fPIC ${LDFLAGS}"
#
export CC=icc
export CXX=icpc
export FC=ifort
export F77=ifort
export F90=ifort
export CPP='icc -E -mcmodel=large'
export CXXCPP='icpc -E -mcmodel=large'
export CPPFLAGS="-DNDEBUG -DpgiFortran ${LDFLAGS}"
#
export CFLAGS=" ${OPTIM}"
export CXXFLAGS=" ${OPTIM}"
export FCFLAGS=" ${OPTIM}"
export F77FLAGS=" ${OPTIM}"
export F90FLAGS=" ${OPTIM}"
#
./configure --prefix=/usr/local/netcdf-ifort/4.4.4 --enable-large-file-tests --with-pic
[/cc]
Changing [cci]config-intel.sh[/cci] to executable form, build as follows:
[cc lang='bash']
username@HOSTNAME:~/Downloads/netcdf-fortran-4.4.4$ chmod a+x config-intel.sh
username@HOSTNAME:~/Downloads/netcdf-fortran-4.4.4$ configure ./config-intel.sh
username@HOSTNAME:~/Downloads/netcdf-fortran-4.4.4$ make
username@HOSTNAME:~/Downloads/netcdf-fortran-4.4.4$ make check
username@HOSTNAME:~/Downloads/netcdf-fortran-4.4.4$ sudo make install
[/cc]
Confirm all the tests passed ([cci]PASS[/cci]) in [cci]make check[/cci]. After installation, [cci]bin[/cci], [cci]include[/cci], and [cci]share[/cci] are created under [cci]/usr/local/netcdf-ifort/4.4.4/[/cci].
Appedn the [cci]PATH[/cci] for [cci]bin[/cci] in [cci]~/.bashrc[/cci].
[cc lang='bash']
export PATH=/usr/local/netcdf-ifort/4.4.4/bin:$PATH
[/cc]

Install X Server

Here we set up X Window. First, X Sever client software should be installed on Windows. I recommend to install [cci]VcXsrv[/cci] on Windows. After installation, start [cci]XLaunch[/cci] on Windows with default parameters on its panel. [cci]X mark[/cci] will appear on Windows' task tray. Placing the cursor on this [cci]X mark[/cci], a number like [cci]0.0[/cci] appears after [cci]HOSTNAME[/cci]. This is the display ID, which is used for setting Ubuntu X Server. Append the following in [cci].bashrc[/cci] and source [cci]bash[/cci].
[cc lang='bash']
export DISPLAY=localhost:0.0
export LIBGL_ALWAYS_INDIRECT=1
[/cc]
Then install the following:
[cc lang='bash']
username@HOSTNAME:~$ sudo apt install x11-apps
[/cc]
Starting [cci]xeyes[/cci], eyes-panel will appear.
[cc lang='bash']
username@HOSTNAME:~$ xeyes
[/cc]
Further, install the following. It will take much time.
[cc lang='bash']
username@HOSTNAME:~$ sudo apt install x11-utils x11-xserver-utils
[/cc]

Install lxde and lxpanel

Install lxde and lxpanel. It will take time.
[cc lang='bash']
username@HOSTNAME:~$ sudo apt install lxde lxpanel
[/cc]

Install Google Chrome

First, install [cci]fonts-liberation[/cci] as a prerequisite.
[cc lang='bash']
username@HOSTNAME:~$ sudo apt install fonts-liberation
[/cc]
Then, download Chrome package.
[cc lang='bash']
username@HOSTNAME:~/Downloads$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
[/cc]
Install Chrome. It will take time.
[cc lang='bash']
username@HOSTNAME:~/Downloads$ sudo apt -f install -y && sudo dpkg -i google-chrome-stable_current_amd64.deb
[/cc]
Start Chrome.
[cc lang='bash']
username@HOSTNAME:~$ google-chrome-stable
[/cc]
Although some errors appear on the terminal, it seems working well.

Set up Python environment by installing Miniconda

I recommend to install Miniconda instead of Anaconda to minimize conflicts among packages.

Install Miniconda

Download Miniconda and invoke installation script.
[cc lang='bash']
username@HOSTNAME:~/Downloads$ wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
username@HOSTNAME:~/Downloads$ bash Miniconda3-latest-Linux-x86_64.sh
[/cc]
Install interactively using default parameters excpet the last option of appending [cci]PATH[/cci] in [cci].bashrc[/cci] choosing [cci]yes[/cci]. Then restart the terminal.

Install packages

After completion of installing Miniconda, first keep it up-to-date.
[cc lang='bash']
username@HOSTNAME:~$ conda update conda
username@HOSTNAME:~$ conda update --all
[/cc]
Next, install basic packages as follows:
[cc lang='bash']
username@HOSTNAME:~$ conda install jupyter notebook pandas matplotlib netcdf4 holoviews geoviews
[/cc]

Create a virtual environment

It may be necessary to use a package that is not the latest version owing to the dependency, which may lead to conflicts among packages. To avoid this, you may construct a virtual environment without polluting existing environments.
You can create the virtual environment using [cci]conda[/cci] command. For example, you can create [cci]myenv[/cci] adopting Python 3.6 as follows:
[cc lang='bash']
username@HOSTNAME:~$ conda create -n myenv python=3.6
[/cc]
You can check available environments using [cci]conda info -e[/cci].
[cc lang='bash']
username@HOSTNAME:~$ conda info -e
# conda environments:
#
base * /home/username/Miniconda3
myenv /home/username/Miniconda3/envs/myenv
[/cc]
The environment with [cci]*[/cci] is the active environment. To activate [cci]myenv[/cci], use [cci]activate myenv[/cci]. You can confirm that [cci]*[/cci] moves to [cci]myenv[/cci] by [cci]conda info -e[/cci].
You can deactivate by [cci][deactivate[/cci].
[cc lang='bash']
username@HOSTNAME:~$ deactivate
[/cc]
You can delete a virtual environment in [cci]base[/cci] environment using [cci]conda remove -n virual-environment-name --all[/cci].
[cc lang='bash']
username@HOSTNAME:~$ conda remove -n myenv --all
[/cc]

Output environmental setting and its restoration

It is easy to reproduce an environment on another machine by writing its environmental setting in a file by using [cci]conda env export -n virtual-environment-name[/cci].
[cc lang='bash']
username@HOSTNAME:~$ conda env export -n myenv >myenv.yaml
[/cc]
The file of [cci]myenv.yaml[/cci] will be created in the current directory.
You can restore the environment using [cci]myenv.yaml[/cci] on another machine.
[cc lang='bash']
username@HOSTNAME:~$ conda env create -f myenv.yaml
[/cc]

References (Some sites are in Japanese)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.