Windowsに開発環境を作る WSL編

WSLのセットアップ

設定変更

「アプリと機能」 >「プログラムと機能 」> 「Windowsの機能の有効かまたは無効化」から、Windows Subsystem Linuxを有効にする。
上記設定後、OSを再起動。
 

Linuxのインストール

MicroSoft Store からubuntuを検索し入手ボタンをクリック。
インストール出来たら、「起動」ボタンを押す
起動すると、初期設定が行われるのか、少し時間がかかる。
初期ユーザのユーザ名とパスワードの設定画面となるので、任意のものを設定する。
 
Installing, this may take a few minutes...Please create a default UNIX user account. The username does not need to match your Windows username.For more information visit: https://aka.ms/wslusers
Enter new UNIX username: gyamin
Enter new UNIX password:Retype new UNIX password:
 

初期設定

SSH設定
$ ssh-keygen -t rsa
 
wslのファイルシステムwindows側とのデータ共有のため?権限周りが普通ではない。777になっていて、変更もできない。
(以下参考)
で、根本的には解決していないようだが、777だと権限問題でコマンドなどが正常に動作しないこともあるので、Linuxからの見た目上755のような権限に設定できるようにマウントする。
  • オプション指定してmountする
$ sudo umount /mnt/c
$ sudo mount -t drvfs C: /mnt/c -o metadata
 
$ mount
C: on /mnt/c type drvfs (rw,relatime,metadata,case=off)
$ mkdir hoge
$ ls -l
drwxrwxrwx 1 gyamin gyamin 4096 Mar 10 20:06 hoge
  • chmoで権限変更(変更可能になった)
$ chmod -R 755 hoge/
$ ls -l
drwxr-xr-x 1 gyamin gyamin 4096 Mar 10 20:06 hoge
  • ubuntu再起動でもオプション指定したマウントを実施する
  • /etc/wsl.confを作成し、以下を記載する。
$ sudo vim /etc/wsl.conf
 
[automount]
enabled = true
options = "metadata"
mountFsTab = false
 
  • .profileにumaskを設定することでデフォルトを設定可能
$ vim .profile
umask 022
$ source .profile

その他設定

$ mkdir /mnt/c/Users/xxx/develop
$ ln -s /mnt/c/Users/xxx/develop ./
~$ ls -l
total 0
lrwxrwxrwx 1 gyamin gyamin 26 Feb 28 21:19 develop -> /mnt/c/Users/xxx/develop
$ cd develop
$ mkdir repos
.fileのコピー
$ ln -s develop/repos/dotFiles/.bash_profile ./
$ ln -s develop/repos/dotFiles/.gitconfig ./
$ ln -s develop/repos/dotFiles/.gitignore ./
$ ln -s develop/repos/dotFiles/.gvimrc ./
$ ln -s develop/repos/dotFiles/.vimrc ./