起こったこと
AtCoderで原因不明のランタイムエラーが起きたので、調査のために手元のUbuntu on WSL2にrbenvでRuby2.3.3をインストールしようとしたら以下のエラーメッセージが出て、インストールが中断されてしまいました。
$ rbenv install 2.3.3
Downloading ruby-2.3.3.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.bz2
Installing ruby-2.3.3...
BUILD FAILED (Ubuntu 18.04 using ruby-build 20191205-4-gf04eb99)
Inspect or clean up the working tree at /tmp/ruby-build.20191229214156.195.oPHCjW
Results logged to /tmp/ruby-build.20191229214156.195.log
Last 10 log lines:
installing rdoc: /home/yagao/.rbenv/versions/2.3.3/share/ri/2.3.0/system
installing capi-docs: /home/yagao/.rbenv/versions/2.3.3/share/doc/ruby
The Ruby openssl extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `apt-get install -y libssl-dev` to fetch missing dependencies.
言われるがままにapt-get install -y libssl-dev
したんですが、インストール済みと言われてしまいました。
$ sudo apt-get install -y libssl-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libssl-dev is already the newest version (1.1.1-1ubuntu2.1~18.04.5).
0 upgraded, 0 newly installed, 0 to remove and 127 not upgraded.
解決策
困り果ててGoogle先生に聞きに行ったら、以下の大変ありがたい記事を見つけることができました。
Ubuntu 18.04上においてruby-buildでruby 2.3.*をインストールする - 有馬総一郎のブログ
答えはここにあったCan’t build on Ubuntu 18.04 (bionic64) · Issue #1199 · rbenv/ruby-build · GitHub
Ruby < 2.4 is not compatible with openssl 1.1.
You need to install libssl1.0-dev.
確認してみると、確かに手元のopensslのバージョンは1.1でした。
$ openssl version
OpenSSL 1.1.0g 2 Nov 2017 (Library: OpenSSL 1.1.1 11 Sep 2018)
あとはサイトにある通りopenssl 1.0をインストールしてうまく行けばいいのですが。。。
$ sudo apt install libssl1.0-dev
$ rbenv install 2.3.3
Downloading ruby-2.3.3.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.3.tar.bz2
Installing ruby-2.3.3...
Installed ruby-2.3.3 to /home/yagao/.rbenv/versions/2.3.3
$ rbenv versions
2.3.3
* 2.6.5 (set by /home/yagao/.rbenv/version)
成功!!(apt
だったりapt-get
だったりしてすみません汗)
おわりに
ほぼほぼ既存の記事の焼き直しなんですが、WSL2上のUbuntuでも同じ対処法が有効だという検証の意味も込めて作成させていただきました。素晴らしい記事を書いてくださった有馬総一郎さん、ありがとうございました。