何かやってみるブログ

興味をもったこと、趣味のこと、技術について色々書きます。

[メモ] Ubuntu22.04でRuby 3.3.0のインストールに失敗してしまったときのメモ

環境

cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

現象

いつも通りインストールしようとすると失敗してしまった。

git -C /home/t-sugiyama/.anyenv/envs/rbenv/plugins/ruby-build pull
rbenv install 3.3.0
rbenv install 3.3.0
==> 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  6491k      0  0:00:02  0:00:02 --:--:-- 6492k
==> Installing openssl-3.1.4...
-> ./config "--prefix=$HOME/.anyenv/envs/rbenv/versions/3.3.0/openssl" "--openssldir=$HOME/.anyenv/envs/rbenv/versions/3.3.0/openssl/ssl" zlib-dynamic no-ssl3 shared
-> make -j 16
-> make install_sw install_ssldirs
==> Installed openssl-3.1.4 to /home/t-sugiyama/.anyenv/envs/rbenv/versions/3.3.0
==> Downloading ruby-3.3.0.tar.gz...
-> curl -q -fL -o ruby-3.3.0.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.0M  100 21.0M    0     0  6485k      0  0:00:03  0:00:03 --:--:-- 6486k
==> Installing ruby-3.3.0...
-> ./configure "--prefix=$HOME/.anyenv/envs/rbenv/versions/3.3.0" "--with-openssl-dir=$HOME/.anyenv/envs/rbenv/versions/3.3.0/openssl" --enable-shared --with-ext=openssl,psych,+
-> make -j 16
*** Following extensions are not compiled:
openssl:
        Could not be configured. It will not be installed.
        /tmp/ruby-build.20231226182216.135700.9f2vHR/ruby-3.3.0/ext/openssl/extconf.rb:33: OpenSSL library directory could not be found in '/home/t-sugiyama/.anyenv/envs/rbenv/versions/3.3.0/openssl/lib'. You might want to fix this error in one of the following ways.
          * Recompile OpenSSL by configuring it with --libdir=lib  to specify the OpenSSL library directory.
          * Recompile Ruby by configuring it with --libdir=<dir> to specify the Ruby library directory.
          * Compile this openssl gem with --with-openssl-include=<dir> and --with-openssl-lib=<dir> options to specify the OpenSSL include and library directories.
        Check /tmp/ruby-build.20231226182216.135700.9f2vHR/ruby-3.3.0/ext/openssl/mkmf.log for more details.
psych:
        Could not be configured. It will not be installed.
        Check /tmp/ruby-build.20231226182216.135700.9f2vHR/ruby-3.3.0/ext/psych/mkmf.log for more details.

BUILD FAILED (Ubuntu 22.04 on x86_64 using ruby-build 20231225-2-g3b79c29)

You can inspect the build directory at /tmp/ruby-build.20231226182216.135700.9f2vHR
See the full build log at /tmp/ruby-build.20231226182216.135700.log

対処

  • エラーメッセージにあるpsych はlibyamlが必要らしいのでlibyamlを入れた。
sudo apt-get install libyaml-dev
  • OpenSSLないじゃんと言われたのでソースをイントールしてbuildしてinstallするときのオプションにディレクトリを渡した。
curl -O https://www.openssl.org/source/openssl-3.1.4.tar.gz
tar zxvf openssl-3.1.4.tar.gz
cd openssl-3.1.4
./Configure
make
sudo make install
RUBY_CONFIGURE_OPTS="--with-openssl-include=$HOME/openssl-3.1.4" rbenv install 3.3.0

成功した。