LoginSignup
2
1

WSL2でrbenvからRubyをビルドしようとしたら、すんなりいかなかった話

Last updated at Posted at 2024-03-25

今回のサマリ

WSL2上のUbuntuでrbenvからRubyをビルドしようとしたら、ライブラリが足りずにエラーが出ました。
足りなかったライブラリは以下の通りです。

  • libyaml
  • fiddle
  • openssl

環境

  • WSL2(windows11)
  • Ubuntu.22.04LTS
  • rbenvのバージョンは以下の通り
 ~$ rbenv -v
 rbenv 1.2.0-87-ge8b7a27

今回の困りごと

今度はWSL2上でのUbuntuの話です。
WSL2上で運用しているUbuntuでrbenvからRubyをビルドしようとしたら、下記のようなエラーを吐かれました。

 $ rbenv install 3.2.3
 ==> Downloading openssl-3.1.4.tar.gz...
 -> curl -q -fL -o openssl-3.1.4.tar.gz https://dqw8nmjcqpjn7.cloudfront.net/840af5366ab9b522bde525826be3ef0fb0af81c6a9ebd84caa600fea1731eee3
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
 100 14.8M  100 14.8M    0     0  20.8M      0 --:--:-- --:--:-- --:--:-- 20.8M
 ==> Installing openssl-3.1.4...
 -> ./config "--prefix=$HOME/.rbenv/versions/3.2.3/openssl" "--openssldir=$HOME/.rbenv/versions/3.2.3/openssl/ssl" zlib-dynamic no-ssl3 shared
 
 BUILD FAILED (Ubuntu 22.04 on x86_64 using ruby-build 20240119)
 
 You can inspect the build directory at /tmp/ruby-build.20240202104107.1400.V97VLf
 See the full build log at /tmp/ruby-build.20240202104107.1400.log

前回と同様に「プロキシじゃないのか!?」「またプロキシなのか!?」と幻術にかかった気分でしたが、今回はどうやら違うようでした。
ちなみに前回はこちら。

なんでなん?

エラー文中で提示されたログファイルを見てみましょう。

 $ sudo less /tmp/ruby-build.20240202104107.1400.log
 
 make[1]: ディレクトリ '/tmp/ruby-build.20231130152200.1900226.I2priR/ruby-3.2.2' から出ます
 Generating RDoc documentation
 /tmp/ruby-build.20231130152200.1900226.I2priR/ruby-3.2.2/lib/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output).
 To eliminate this warning, please install libyaml and reinstall your ruby.
 uh-oh! RDoc had a problem:
 cannot load such file -- psych
 
 run with --debug for full backtrace
 make: *** [uncommon.mk:598: rdoc] エラー 1
 external command failed with status 2

というわけで、please install libyaml and reinstall your ruby.とあるように、libyamlをインストールする必要があります。

libyamllibyaml-devというパッケージ名で提供されています。

 $ sudo apt install libyaml-dev

これで解決できたでしょう。

まだ足りてない

気を取り直してインストールし直しと思いきや、また新しいエラーが出てきました。

$ rbenv install 3.2.3
 ==> Downloading openssl-3.1.4.tar.gz...
 -> curl -q -fL -o openssl-3.1.4.tar.gz https://dqw8nmjcqpjn7.cloudfront.net/840af5366ab9b522bde525826be3ef0fb0af81c6a9ebd84caa600fea1731eee3
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
 100 14.8M  100 14.8M    0     0  33.9M      0 --:--:-- --:--:-- --:--:-- 34.0M
 ==> Installing openssl-3.1.4...
 -> ./config "--prefix=$HOME/.rbenv/versions/3.2.3/openssl" "--openssldir=$HOME/.rbenv/versions/3.2.3/openssl/ssl" zlib-dynamic no-ssl3 shared
 -> make -j 12
 -> make install_sw install_ssldirs
 ==> Installed openssl-3.1.4 to /home/s220125/.rbenv/versions/3.2.3
 ==> Downloading ruby-3.2.3.tar.gz...
 -> curl -q -fL -o ruby-3.2.3.tar.gz https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.3.tar.gz
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
 100 19.6M  100 19.6M    0     0  5089k      0  0:00:03  0:00:03 --:--:-- 5088k
 ==> Installing ruby-3.2.3...
 -> ./configure "--prefix=$HOME/.rbenv/versions/3.2.3" "--with-openssl-dir=$HOME/.rbenv/versions/3.2.3/openssl" --enable-shared --with-ext=openssl,psych,+
 -> make -j 12
 *** Following extensions are not compiled:
 fiddle:
         Could not be configured. It will not be installed.
         /tmp/ruby-build.20240202115328.67550.je5xfV/ruby-3.2.3/ext/fiddle/extconf.rb:73: missing libffi. Please install libffi or use --with-libffi-source-dir with libffi source location.
         Check /tmp/ruby-build.20240202115328.67550.je5xfV/ruby-3.2.3/ext/fiddle/mkmf.log for more details.
 openssl:
         Could not be configured. It will not be installed.
         /tmp/ruby-build.20240202115328.67550.je5xfV/ruby-3.2.3/ext/openssl/extconf.rb:101: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
         Check /tmp/ruby-build.20240202115328.67550.je5xfV/ruby-3.2.3/ext/openssl/mkmf.log for more details.
 
 BUILD FAILED (Ubuntu 22.04 on x86_64 using ruby-build 20240119)
 
 You can inspect the build directory at /tmp/ruby-build.20240202115328.67550.je5xfV
 See the full build log at /tmp/ruby-build.20240202115328.67550.log

ログは以下の通り。

inux
 *** Following extensions are not compiled:
 fiddle:
         Could not be configured. It will not be installed.
         /tmp/ruby-build.20240202115328.67550.je5xfV/ruby-3.2.3/ext/fiddle/extconf.rb:73: missing libffi. Please install libffi or use --with-libffi-source-dir with libffi source location.
         Check ext/fiddle/mkmf.log for more details.
 openssl:
         Could not be configured. It will not be installed.
         /tmp/ruby-build.20240202115328.67550.je5xfV/ruby-3.2.3/ext/openssl/extconf.rb:101: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
         Check ext/openssl/mkmf.log for more details.
 *** Fix the problems, then remove these directories and try again if you want.

まだ足りてないライブラリがあったようです。
犯人はfiddleopensslのようです。
容疑者さえ絞り込められれば、あとはサクサク対処可能です。

$ sudo apt install libffi-dev
$ sudo apt install libssl-dev

再インストールしてみましょう。

 $ rbenv install 3.2.3
 ==> Downloading ruby-3.2.3.tar.gz...
 -> curl -q -fL -o ruby-3.2.3.tar.gz https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.3.tar.gz
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
 100 19.6M  100 19.6M    0     0  6475k      0  0:00:03  0:00:03 --:--:-- 6475k
 ==> Installing ruby-3.2.3...
 -> ./configure "--prefix=$HOME/.rbenv/versions/3.2.3" --enable-shared --with-ext=openssl,psych,+
 -> make -j 12
 -> make install
 ==> Installed ruby-3.2.3 to /home/hogehoge/.rbenv/versions/3.2.3

ちゃんとインストールできたか確認してみます。

 $ rbenv version
 3.2.3 (set by /home/hogehoge/.ruby-version)

できました。

なんでこういうことが起きるのか

Ubuntu端末ではプロキシを除いてスムーズにRubyのビルドはできたのに、今回のWSL2上のUbuntuではライブラリの依存関係でだいぶ詰まりました。

WSL2に乗っかってるUbuntuではsystemdがデフォルトで機能していなかったりと、通常のディストリビューションのUbuntuとでは色々と勝手が違うようです。

このあたりも時間がある時にまとめていきたいと思います。ほんとこういうとこ、windowsってめんどくさい。

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1