(1) WSL を起動する。以降はWSL内での操作。
wsl -d Ubuntu-22.04

(2) 以下のコマンドを実行し、sudo の際にパスワード不要にする。
sudo sed -e 's/%sudo\tALL=(ALL:ALL) ALL/%sudo\tALL=NOPASSWD: ALL/' /etc/sudoers | EDITOR=tee sudo -E visudo

(3) 以下のコマンドを実行し、タイムゾーンを日本に設定する。
sudo timedatectl set-timezone Asia/Tokyo

(4) 以下のコマンドを実行し、sudoの際にプロキシを使えるようにする。
sudo sed -e 's/#Defaults:%sudo env_keep += "http_proxy https_proxy ftp_proxy all_proxy no_proxy"/Defaults:%sudo env_keep += "http_proxy https_proxy ftp_proxy all_proxy no_proxy"/' /etc/sudoers | EDITOR=tee sudo -E visudo

(5) 以下のコマンドを実行し、apt リポジトリを国内に設定する。
cat << '_EOF' | sudo tee /etc/apt/ubuntu.mirrors
http://ftp.yz.yamagata-u.ac.jp/pub/linux/ubuntu/archives/
http://www.ftp.ne.jp/Linux/packages/ubuntu/archive/
http://ftp.jaist.ac.jp/pub/Linux/ubuntu/
http://ftp.riken.jp/Linux/ubuntu/
http://ubuntutym.u-toyama.ac.jp/ubuntu/
_EOF
sudo sed -i -e 's,http://archive.ubuntu.com/ubuntu,mirror+file:/etc/apt/ubuntu.mirrors,' /etc/apt/sources.list.d/ubuntu.sources

(6) 以下のコマンドを実行し、初回アップデートを実施する。
sudo apt -y update
sudo apt -y upgrade

(7) 以下のコマンドを実行し、日本語対応を行う。
sudo apt -y install \
 language-pack-ja \
 locales \
 locales-all

(8) 以下のコマンドを実行し、デフォルト言語を英語に設定する。
sudo update-locale LANG=en_US.UTF-8

(9) 以下のコマンドを実行し、基本コマンドをインストールする。
sudo apt -y install \
  debianutils \
  ed \
  expect \
  gawk \
  git \
  git-core \
  less \
  python3 \
  python-is-python3 \
  python3-requests \
  screen \
  sed \
  subversion \
  sudo \
  vim
sudo apt -y install \
  curl \
  dnsutils \
  ftp \
  openssh-client \
  rsync \
  rsyslog \
  tcpdump \
  traceroute \
  wget

(10) 以下のコマンドを実行し、/bin/sh が実行された際は /bin/bash が実行されるようにする。
sudo rm /bin/sh
sudo ln -s /bin/bash /bin/sh

(11) 以下のコマンドを実行し、アーカイバをインストールする。
sudo apt -y install \
 bzip2 \
 genisoimage \
 gzip \
 p7zip \
 p7zip-full \
 tar \
 unzip

(12) 以下のコマンドを実行し、フォントをインストールする。
sudo apt -y install \
 fontconfig \
 fonts-mplus
sudo fc-cache -f

(13) 以下のコマンドを実行し、Windowsのフォントを使用可能にする。
sudo ln -s /mnt/c/Windows/Fonts /usr/share/fonts/windows
sudo fc-cache -f

(14) 以下のコマンドを実行し、GUIライブラリをインストールする。
sudo apt -y install \
 x11-apps \
 xserver-xorg \
 xterm

(15) 以下のコマンドを実行し、開発環境をインストールする。
sudo apt -y install \
 automake \
 bison \
 build-essential \
 cmake \
 gcc \
 gdb \
 libtool \
 make

(16) 以下のコマンドを実行し、zshをインストールする。
sudo apt -y install zsh

(17) 以下のコマンドを実行し、zshを有効化する。
zsh

(18) 以下のコマンドを実行し、zshをデフォルトのシェルにする。
sudo usermod -s /usr/bin/zsh $USER

(19) 以下のコマンドを実行し、bashの設定の削除を行う。
rm ~/.bash* ~/.profile

(20) 以下のコマンドを実行し、ログイン時のシステムメッセージの抑止を行う。
touch ~/.hushlogin
rm -rf ~/.motd_shown ~/.cache

(21) 以下のファイル/フォルダを /home/wsl に格納する。(Windowsで操作)
.ssh .exrc .screenrc .vimrc .Xdefaults .zprofile .zsh_aliases .zshenv .zshrc

(22) 以下のコマンドを実行し、権限を整える。
chmod 750 $HOME
find $HOME -maxdepth 1 -type f | xargs chmod 640
find $HOME -maxdepth 1 -type d | xargs chmod 750
chmod 700 $HOME/.ssh
chmod 600 $HOME/.ssh/*

(23) 以下のコマンドを実行し、screen コマンドの設定を行う。
cat << 'EOL' | tee -a ~/.zprofile.local

if [ "`uname -r | grep -i microsoft`" ]; then
  export SCREENDIR="${HOME}/.local/run/screen"
  mkdir -p "${SCREENDIR}"
  chmod 700 "${SCREENDIR}"
fi
EOL

(24) 以下のコマンドを実行し、GUIアプリケーションの日本語入力対応を行う。
sudo apt install -y \
 dbus-x11 fcitx-bin fcitx-mozc mozc-utils-gui x11-xkb-utils
im-config -n fcitx

(25) 以下のコマンドを実行し、自身の環境に合わせてGUIのキーマップを変更する。
setxkbmap -layout us ※英語キーボードの場合
setxkbmap -layout jp ※日本語キーボードの場合

(26) 以下のコマンドを実行し、fcitxの自動起動設定を行う。
cat << 'EOL' | tee -a ~/.zprofile.local

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export DefaultIMModule=fcitx
fcitx-autostart &> /dev/null
EOL
. ~/.zprofile.local

(27) 以下のコマンドを実行し、WSLの設定の変更を行う。
cat << 'EOL' | sudo tee /etc/wsl.conf
[interop]
enabled = false
appendWindowsPath = false

[boot]
systemd = true

[user]
default = wsl
EOL

(28) 一度、WSLを再起動する。以降はWindowsでの操作。
×ボタンで閉じる。

(29) WSL を起動する。以降はWSL内での操作。
wsl -d Ubuntu-22.04 --shutdown
wsl -d Ubuntu-22.04

(30) 以下のコマンドを実行し、キーボードの追加を行う。
fcitx-configtool
=> 一番上にあるキーボードが使用しているキーボードと配列が異なっている場合は、-ボタンで削除する。
=> 左下の+ボタン
=> "Only how currentlanguage" のチェックを外す
=> "Keyboard - English (US)" か "Keyboard - Japanese" を選択してOK
=> 左下の+ボタン
=> "Only how currentlanguage" のチェックを外す
=> "Mozc" を選択してOK
=> ×ボタンで終了

(31) 以下のコマンドを実行し、mozcの設定(辞書、学習の設定等)を行う。
/usr/lib/mozc/mozc_tool --mode=config_dialog

(32) 以下のコマンドを実行し、Workspaceを作成する。
mkdir -p ~/Workspace