LoginSignup
1
0

More than 3 years have passed since last update.

rbenvでruby-1.8.7をインストールするためにgccのバージョンを変更

Last updated at Posted at 2021-03-23

ruby-1.8.7をインストールする必要があり、rbenvでインストールしようとしたところ、gccのコンパイルエラーが出てしまいました。
gccのバージョンを変えて解決する方法があったので、載せておきます。

使用OS

MacOS Big Sur 11.2.1

まずはインストールしてみる

$ rbenv install 1.8.7-p374

rbenvDownloading ruby-1.8.7-p374.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p374.tar.bz2
Installing ruby-1.8.7-p374...

WARNING: ruby-1.8.7-p374 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

ruby-build: using readline from homebrew

BUILD FAILED[m (macOS 11.2.1 using ruby-build 20210309)

Inspect or clean up the working tree at /var/folders/w5/x4p8lz7s3s9dbn_vycgzwndh0000gr/T/ruby-build.20210323095308.55162.usAu38
Results logged to /var/folders/w5/x4p8lz7s3s9dbn_vycgzwndh0000gr/T/ruby-build.20210323095308.55162.log

Last 10 log lines:
    return rb_file_sysopen_internal(io_alloc(rb_cFile), fname, flags, mode);
                                                        ^~~~~
io.c:3449:31: warning: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
        rb_file_sysopen_internal(io, path, flags, fmode);
                                     ^~~~
1 warning generated.
1 warning generated.
1 warning generated.
2 warnings generated.
11 warnings generated.

なんかだめみたい。

調査開始

Results logged to /var/folders/w5/x4p8lz7s3s9dbn_vycgzwndh0000gr/T/ruby-build.20210323095308.55162.log
とあるので、ログをみてみると

ruby-build.20210323095308.55162.log
eval.c:7288:2: error: implicit declaration of function 'rb_thread_join' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        rb_thread_join(owner->thread, -1.0);
        ^

というエラー。
よくわからないけど、コンパイルのエラーが起きているみたい。

とりあえずググる。
同じような問題がissueに上がっていたのでチェック。

yatsuさんのコメントにUsing gcc-6 or other versions may help.とあったので、コンパイラのバージョンを変えてみることにした。

gccバージョン6がいけそうなので、現在のgccの場所とバージョンを確認。

$ which gcc
/usr/bin/gcc

$ gcc --version
gccConfigured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

どうやら12.0.0だったみたい。
他のバージョンはhomebrewでインストール。

brew install gcc@6

gcc-6がインストールできていることを確認。

$ ll /usr/local/bin/gcc-6
/usr/local/bin/gcc-6 -> ../Cellar/gcc@6/6.5.0_6/bin/gcc-6

※Cellarのディレクトについては以下を参考とさせていただきました。

次にgccのパスをバージョン6を参照するようにシンボリックリンクを作成。

ln -s /usr/local/bin/gcc-6 /usr/local/bin/gcc

gccのパスは/usr/bin/gccとなっていたので、先に/usr/local/bin/gccを参照してくれるようにする必要がある。
私の場合は~/.zshrcに以下を追加しました。

$ vi ~/.zshrc
PATH=/usr/local/bin:/usr/local/sbin:$PATH

gccの場所とバージョンを再確認すると。。

$ which gcc
/usr/local/bin/gcc
$ gcc --version
gcc (Homebrew GCC 6.5.0_6) 6.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

バージョンが6になっていることを確認できます。

この設定でrbenv install 1.8.7-p374に成功することができました!

$ rbenv versions
* system 
  1.8.7-p374
  3.0.0

参考

gccのコンパイラの変更方法は以下を参照させていただきました。

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