exits

勉強記録

Cygwinでgo入門を諦めてWSL環境を作ったがCygwinでも大丈夫だった

今年もなにか新しい言語の勉強をしてみなくては…
ということでA Tour of Goをやってみようと、いつも通りCygwin上で設定を始めました。
しかしうまくいかなかったので、Cygwinを諦めてWSLに手を出すことにしました。 記事を書きながら試したことをなぞっていくと、今度はCygwinでうまくいってしまいました。

Go on Cygwinを入れた話と、それとは関係なくWSL環境を整えた話を書きます。

Go on Cygwin

Windowsでgoをインストール

ダウンロードページ からgo1.12.9.windows-amd64.msi をダウンロードし、普通にインストールしました。
(僕がこの辺りを触っていたのは2週間前だったので1.12.9だったんですが、今見たら1.13がStableになっていてびっくり)

go get

Cygwinからgoを起動できたのでA Tour of Goを取ってこようとすると

$ go get github.com/atotto/go-tour-jp/gotour
# cd .; git clone https://github.com/atotto/go-tour-jp C:\Users\yue\go\src\github.com\atotto\go-tour-jp
Cloning into 'C:\Users\yue\go\src\github.com\atotto\go-tour-jp'...
fatal: unable to find remote helper for 'https'
package github.com/atotto/go-tour-jp/gotour: exit status 128

そりゃCygwinはC:なんて知らないからそうだよな、ということでGOPATHを変えてみました。

$ export GOPATH='/home/yue/go'
$ go get github.com/atotto/go-tour-jp/gotour
go: GOPATH entry is relative; must be absolute path: "/home/yue/go".
For more details see: 'go help gopath'

???

こちらの記事を参考に、window形式のパスに。

$ export GOPATH=c:\\cygwin\\home\\yue\\go    # NG
$ echo $GOPATH
c:%

$ export GOPATH='c:\\cygwin\\home\\yue\\go'  # OK
$ echo $GOPATH
c:\cygwin\home\yue\go

$ go get github.com/atotto/go-tour-jp/gotour
# cd .; git clone https://github.com/atotto/go-tour-jp c:\cygwin\home\yue\go\src\github.com\atotto\go-tour-jp
Cloning into 'c:\cygwin\home\yue\go\src\github.com\atotto\go-tour-jp'...
fatal: unable to find remote helper for 'https'
package github.com/atotto/go-tour-jp/gotour: exit status 128

curl-devがリンクできていないらしい。

gitを入れ直してみます。

$ apt-cyg remove git
$ apt-cyg install libcurl-devel
$ git clone git@github.com:git/git.git
$ cd git
$ ./configure --prefix=/usr/local --with-curl --with-expat
$ make NO_TCLTK=1 install

$ go get github.com/atotto/go-tour-jp/gotour
$ echo $?
0
$ gotour
zsh: command not found: gotour

$ export PATH="$HOME/go/bin:$PATH"
$ gotour
2019/09/09 00:56:21 Serving content from c:\cygwin\home\yue\go\src\github.com\atotto\go-tour-jp
2019/09/09 00:56:22 A browser window should open. If not, please visit http://127.0.0.1:3999
2019/09/09 00:56:23 accepting connection from: 127.0.0.1:55902

できた🎉

Cygwinでがんばるのはそもそも2週間前にやっていたので、何でだめだったのか思い出せません。
http://go.googlesource.com/go から取ってきてビルドしようともしていたはず…?

結局できたのでよかったということにします。

WSL環境をつくった

Kali Linuxをインストール

コントロールパネルからWSLを有効にするのは昔やってありました。
Microsoft StoreでWSLと検索し、ディストリビューションを選びます。
(今見たらFedoraめっちゃ割引しとるやんけ!!)
f:id:yue82:20190908230843p:plain:w400

いつもUbuntuだったのでちょっと変えてみるか、ということでKali Linuxを選択。
あとは流れですすめると、スタートメニューから選べるようになります。
f:id:yue82:20190908233631p:plain

起動するとユーザ名とパスワード設定があり、しばらく待つと普通に使えます。
あとは普段どおりに色々。

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install gcc g++ make git wget curl tmux zsh ssh

$ sudo apt install python3
$ sudo ln -s /usr/bin/python3 /usr/bin/python
$ sudo apt install python3-pip

$ sudo apt install ruby
$ sudo gem install tmuxinator

$ ssh-keygen -t rsa
$ cat .ssh/id_rsa.pub
$ ssh -T git@github.com
$ git clone git@github.com:yue82/dotfiles.git
$ cd dotfiles/
$ ./setconfig.sh

emacs

$ sudo apt install libncurses5-dev
$ mkdir ~/tools
$ cd ~/tools
$ wget 'https://ftp.gnu.org/gnu/emacs/emacs-25.3.tar.gz'
$ tar zvxf emacs-25.3.tar.gz
$ cd emacs-25.3
$ ./configure --without-x
$ make
$ sudo make install

まだemacs26用にinit.elを書き直していないのでemacs25です。 これはいつか一斉に26に上げないと…

パッケージインストールのため、 ~/.emacs.d/package.el を開いて eval-buffer

Contacting host: orgmode.org:80
Opening TLS connection to ‘orgmode.org’...
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 orgmode.org’...failed
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 orgmode.org --protocols ssl3’...failed
Opening TLS connection with ‘openssl s_client -connect orgmode.org:443 -no_ssl2 -ign_eof’...failed
Opening TLS connection to ‘orgmode.org’...failed
error in process filter: url-http: Could not create connection to orgmode.org:443
error in process filter: Could not create connection to orgmode.org:443

gnutls-cliがそもそもなかったので入れます。

$ sudo apt install gnutls-bin libgnutls28-dev

再びpackage.elで eval-buffer

Opening TLS connection to ‘marmalade-repo.org’...
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 marmalade-repo.org’...failed
Opening TLS connection with ‘gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 marmalade-repo.org --protocols ssl3’...failed
Opening TLS connection with ‘openssl s_client -connect marmalade-repo.org:443 -no_ssl2 -ign_eof’...failed
Opening TLS connection to ‘marmalade-repo.org’...failed
error in process filter: url-http: Could not create connection to marmalade-repo.org:443
error in process filter: Could not create connection to marmalade-repo.org:443
$ gnutls-cli --x509cafile /etc/ssl/certs/ca-certificates.crt -p 443 marmalade-repo.org
Processed 128 CA certificate(s).
Resolving 'marmalade-repo.org:443'...
Connecting to '80.69.77.43:443'...
- Certificate type: X.509
- Got a certificate list of 1 certificates.
- Certificate[0] info:
 - subject `CN=marmalade-repo.org,OU=PositiveSSL,OU=Domain Control Validated', issuer `CN=COMODO RSA Domain Validation Secure Server CA,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB', serial 0x5f7ce5cf6602297b4cbd14639b670e7d, RSA key 2048 bits, signed using RSA-SHA256, activated `2015-07-12 00:00:00 UTC', expires `2018-07-11 23:59:59 UTC', pin-sha256="6SxP5yqDCUEkRqRN5ZH0AKbV7yjoI74Gnmes2+tN75U="
         Public Key ID:
                     sha1:aba6d76ab3d363fa190d654160236eefd32a46dc
                             sha256:e92c4fe72a8309412446a44de591f400a6d5ef28e823be069e67acdbeb4def95
                             Public Key PIN:
                                         pin-sha256:6SxP5yqDCUEkRqRN5ZH0AKbV7yjoI74Gnmes2+tN75U=

- Status: The certificate is NOT trusted. The certificate issuer is unknown. The certificate chain uses expired certificate.
*** PKI verification of server certificate failed...
*** Fatal error: Error in the certificate.

No git commits in months and an expired TLS certificate are an indication that marmalade is dead. I would advice removing it as package repository.

marmaladeは死んだ。

ファイルの場所

Windows -> WSL


C:\Users\yue\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalState\rootfs\home\yue

WSL -> Windows

$ ls /mnt
c/  d/  e/

再起動

$ wslconfig.exe /l            # 登録されているディストリビューションを確認
$ wslconfig.exe /t kali-linux # kali-linuxを再起動

WSLtty

標準のターミナルは画面の設定なんかがちょっと微妙なので、使い慣れたminttyのWSL版を入れます。


f:id:yue82:20190908233812p:plain

wsl-open

xdg-open的なことをしたいので入れます。

# .zshrc
case ${OSTYPE} in
    linux*)
        if uname -r | grep -i 'microsoft' > /dev/null ; then
            alias open=wsl-open
        else
            alias open=xdg-open
        fi
        ;;
esac

ただし、wsl-openはファイルの場所によってはコピーされるらしい。

wsl-open は、DrvFs ( /mnt/* 以下 ) はそのまま Windows の規定のアプリに渡されるが、VolFs ( /mnt 以外 ) は 一旦 Windows のテンポラリフォルダにコピーされてから実行される ので注意が必要。

また、alias xdg-open=wsl-open としても、emacsのneotreeからは Searching for program: No such file or directory, xdg-open と言われて開けません。 同じようなソフトは他にもありそうなので試してみようかな。

Go on WSL

$ sudo apt install golang-go
$ export GOPATH=$HOME/go
$ export PATH=$PATH:$GOPATH/bin
$ go get github.com/atotto/go-tour-jp/gotour
$ gotour
2019/09/09 02:16:01 Serving content from /home/yue/go/src/github.com/atotto/go-tour-jp
2019/09/09 02:16:02 Please open your web browser and visit http://127.0.0.1:3999

こちらはあっさり動きました🎉

感想

どちらもちゃんと動いてよかったです。
f:id:yue82:20190909021029p:plain:w400

ただ、ちゃんと動いてしまったので脱Cygwinするべきかどうか悩ましい…
ノートPCや会社のWindowsはまだWindows10にしていないので、WSLに揃えられるようになるまでは踏ん切りがつかなさそうです。