LoginSignup
3
2

さくらレンタルサーバーで ruby 3.3.0 をビルド

Last updated at Posted at 2023-12-29

はじめに

さて,クリスマスといえばRubyのメジャーアップデートですね.早速 去年と同じ方法 で ruby 3.3.0 をインストールしてみましょう.

==> Installing ruby-3.3.0...
-> ./configure "--prefix=$HOME/.rbenv/versions/3.3.0" --enable-shared --with-ext=openssl,psych,+ --disable-install-rdoc --with-openssl-dir=/usr/local "--with-libyaml-dir=$HOME/local"
-> make -j 8

BUILD FAILED (FreeBSD 13.0 on amd64 using ruby-build 20231225-2-g3b79c293)

You can inspect the build directory at /home/cycloawaodorin/tmp/ruby-build.20231229170435.10771.KdS07E
See the full build log at /home/cycloawaodorin/tmp/ruby-build.20231229170435.10771.log

おや,ビルドに失敗してしまいました.ログを見てみましょう.

(前略)
--- exts.mk ---
configuring digest
configuring digest/bubblebabble
configuring digest/md5
--- enc ---
--- enc/gb2312.o ---
compiling ./enc/gb2312.c
--- exts.mk ---
Killed
*** [ext/digest/exts.mk] Error code 137

make[1]: stopped in /home/cycloawaodorin/tmp/ruby-build.20231229170435.10771.KdS07E/ruby-3.3.0
--- trans ---
*** [trans] Error code 6

make: stopped in /home/cycloawaodorin/tmp/ruby-build.20231229170435.10771.KdS07E/ruby-3.3.0
--- enc ---
*** [enc] Error code 6

make: stopped in /home/cycloawaodorin/tmp/ruby-build.20231229170435.10771.KdS07E/ruby-3.3.0
--- exts.mk ---
1 error

make[1]: stopped in /home/cycloawaodorin/tmp/ruby-build.20231229170435.10771.KdS07E/ruby-3.3.0
*** [exts.mk] Error code 2

make: stopped in /home/cycloawaodorin/tmp/ruby-build.20231229170435.10771.KdS07E/ruby-3.3.0
3 errors

make: stopped in /home/cycloawaodorin/tmp/ruby-build.20231229170435.10771.KdS07E/ruby-3.3.0
external command failed with status 2

???
何が原因でしょうか.よくわかりません.

原因

新しいバージョンのGCCを試してみようとビルドを試みたものの,こちらのビルドも失敗.ググって見たところ,あるフォーラム議論 が見つかりました.

xg++: fatal error: Killed signal terminated program cc1plus
In almost every cases, this means ran out of memory

ああ,これはありえそうです.さほどメモリが潤沢ではないのに,make -j 8は厳しいかもしれません.

解決法

次の環境変数を設定すればビルドできます.

MAKEOPTS="-j1"

他の環境変数と合わせると,実行すべきコマンドは

$ CC=gcc MAKEOPTS="-j1" RUBY_CONFIGURE_OPTS="--with-openssl-dir=/usr/local --with-libyaml-dir=$HOME/local" TMPDIR="$HOME/tmp" rbenv install 3.3.0

となります.libyaml-devは 前回の記事 の方法でビルドしておきましょう.

==> Installing ruby-3.3.0...
-> ./configure "--prefix=$HOME/.rbenv/versions/3.3.0" --enable-shared --with-ext=openssl,psych,+ --disable-install-rdoc --with-openssl-dir=/usr/local "--with-libyaml-dir=$HOME/local"
-> make -j1
-> make install
==> Installed ruby-3.3.0 to /home/cycloawaodorin/.rbenv/versions/3.3.0

無事ビルドできました.

というわけで,makeを8並列実行してはメモリ不足でビルドに失敗するので,並列実行をやめましょうということでした.

ちなみに GCC 13.2 は MAKEOPTS="-j1" でもビルドに失敗したので,使いたい場合はローカルマシンでクロスコンパイルしてアップロードする必要がありそうです.

追記

Killed
*** [ext/digest/exts.mk] Error code 137

どうやら137というのがメモリ不足のしるしみたいですね."Killed"というのもメモリー使い切りで発生させたことがあった気がします.

3
2
0

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
3
2