LoginSignup
1
1

More than 5 years have passed since last update.

今さらだが macOS High Sierra に Ruby 1.8.7 をソースビルドでインストールしてみる

Posted at

Fukuoka.rb にお邪魔して色々試し、 @udzura さんにそそのかされた推されたので投稿します。

経緯

最近購入した MackBook Pro に Ruby 1.8.7 をインストールしたかったが、rbenv からインストールすることができなかった。Ruby 1.8.7 をビルドするにあたり apple-gcc42 を使用していたが、 homebrew/dupes が廃止になり apple-gcc42 自体がインストールされなくなっていた。だけど、どうしてもインストールしたいのでソースビルドでインストールすることにした。

※ 「こうすれば rbenv でインストールできるよ!」とご存知の方、ご一報ください。

インストールしたい環境

  • macOS High Sierra (10.13.4)
  • MacBook Pro (15-inch, 2017)

前提条件

  • Xcode / Xcode Command Line Tools はインストール済み
  • GitHub から clone できる状態にしている

やったこと

Ruby 1.8.7 のソースを落としてきてビルドしてみる

ビルドの手順は README の「How to compile and install」を素直に実行します。

$ git clone git@github.com:ruby/ruby.git ruby_1_8_7
$ cd ruby_1_8_7
$ git checkout -b ruby_1_8_7 origin/ruby_1_8_7
$ autoconf
$ ./configure
$ make
(中略)
  :
Find Tcl/Tk libraries. Make tcltklib.so which is required by Ruby/Tk.
gcc -I. -I../.. -I../../. -I../.././ext/tk -DHAVE_RB_SAFE_LEVEL -DHAVE_RB_HASH_LOOKUP -DHAVE_RB_PROC_NEW -DHAVE_RB_OBJ_TAINT -DHAVE_ST_PTR -DHAVE_ST_LEN -DRUBY_VERSION=\"1.8.7\" -DRUBY_RELEASE_DATE=\"2014-01-28\"  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -DWITH_TCL_ENABLE_THREAD=0 -fno-common -g -O2 -pipe -fno-common   -c stubs.c
In file included from stubs.c:10:
/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found
#       include <X11/Xlib.h>
                ^~~~~~~~~~~~
1 error generated.
make[1]: *** [stubs.o] Error 1
make: *** [all] Error 1

コンパイルに失敗しました。ヘッダーファイルがないらしいです。

ぐぐる

macでx11/xlib.hの参照

ズバリな感じがしたので、まずは XQuartz をインストールします。dmg ファイルをダウンロードしてインストールすれば大丈夫です。

再度ビルド

$ make clean
$ make CC='gcc -I/opt/X11/include'
(中略)
  :
45 warnings generated.
cc -dynamic -bundle -undefined suppress -flat_namespace -o ../../.ext/i686-darwin17.5.0/zlib.bundle zlib.o -L. -L../.. -L.     -lz  -ldl -lobjc
making ruby
gcc -I/opt/X11/include -g -O2 -pipe -fno-common    -DRUBY_EXPORT  -L.    main.o  -lruby-static -ldl -lobjc   -o ruby

確かに警告 45 個出てますけど、コンパイルは出来たようです。

インストール

$ make install
./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb  ./instruby.rb --make="/Applications/Xcode.app/Contents/Developer/usr/bin/make" --dest-dir="" --extout=".ext" --mflags="" --make-flags="" --data-mode=0644 --prog-mode=0755 --installed-list .installed.list --mantype="doc"
installing binary commands
installing command scripts
installing library scripts
installing headers
installing manpages
installing extension objects
installing extension scripts

何か成功したっぽいので確認してみます。

$ /usr/local/bin/ruby --version
ruby 1.8.7 (2014-01-28 patchlevel 376) [i686-darwin17.5.0]

無事インストールできたようです。

まとめ

最初やった時は make CC='gcc -I/opt/X11/include' を実行した後に「zlib が見つからない」みたいなエラーが出てつまづいたのですが、何故か再現せずインストールに成功しました。
また、X11/Xlib.h が見つからないエラーについては @udzura さんから「tk じゃないすかね?」と助言をもらいました。なので README にある通り、ext/Setup の tk のコメントマークを削除すればオプション指定なしの make でコンパイルが成功するかもしれません。その場合 XQuartz のインストールが必要かどうかは確認していません。実際試された方、ご一報ください。

最後に

この記事は需要あるのかな?

1
1
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
1
1