5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rbenvでruby2.1.1がインストールできないので、ソースコードからmake installでコンパイルした

Posted at

※ シェルはzshでの作業です。

Everyday Rails - RSpecによるRailsテスト入門を購入したので、チュートリアルをこなしていこうと思ったら、rbenv: version '2.1.1' is not installedとターミナルで表示されました。どうやら.ruby-versionというファイルに2.1.1を使用するように書かれていたみたいです。しかしrbenvに2.1.1のrubyは入っていません。そのことを言っているみたいです。じゃあ、rbenvでインストールすればいいのかと思ったら、エラーが出て失敗しました。brewとパッケージのアップグレードを行ってもダメでした。

 % rbenv install 2.1.1
Downloading ruby-2.1.1.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/c843df31ae88ed49f5393142b02b9a9f5a6557453805fd489a76fbafeae88941
Installing ruby-2.1.1...

BUILD FAILED (OS X 10.10.3 using ruby-build 20150818)

Inspect or clean up the working tree at /var/folders/4s/5nw37tss5qx05r8x1r3sqx2h0000gn/T/ruby-build.20150828133828.57290
Results logged to /var/folders/4s/5nw37tss5qx05r8x1r3sqx2h0000gn/T/ruby-build.20150828133828.57290.log

Last 10 log lines:
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for cd using physical directory... cd -P
checking whether CFLAGS is valid... yes
checking whether LDFLAGS is valid... no
configure: error: something wrong with LDFLAGS="-L/Users/mitsuru/.rbenv/versions/2.1.1/lib "
make: *** No targets specified and no makefile found.  Stop.

 % ls /Users/mitsuru/.rbenv/versions/2.1.1/lib
ls: /Users/mitsuru/.rbenv/versions/2.1.1/lib: No such file or directory

 % brew update
Already up-to-date.

# ruby-buildを再インストールする
 % ruby-build --version
ruby-build 20150818
 % brew upgrade ruby-build
Error: ruby-build 20150818 already installed
 % brew uninstall ruby-build
Uninstalling /usr/local/Cellar/ruby-build/20150818... (168 files, 712K)
 % brew install ruby-build
==> Downloading https://homebrew.bintray.com/bottles/ruby-build-20150818.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/ruby-build-20150818.yosemite.bottle.tar.gz
==> Pouring ruby-build-20150818.yosemite.bottle.tar.gz
<img data-mce-resize="false" data-mce-placeholder="1" data-wp-emoji="1" class="emoji" draggable="false" alt="🍺" src="http://s.w.org/images/core/emoji/72x72/1f37a.png">  /usr/local/Cellar/ruby-build/20150818: 168 files, 712K

 % rbenv install 2.1.1  
# 同じエラー

ぐぐってみると、下記の記事のこの回避策が載っていました。rbenvのインスール時にkオプションをつけることでソースコードを残すことができるらしいです。なので自分でコンパイルすることになります。パスは自分のmac用に書き換えました。

Satoryu's Diary(OpenShift支店)(2015-06-17)

 % rbenv install -k 2.1.1
 % cd /Users/mitsuru/.rbenv/sources/2.1.1/ruby-2.1.1
 % ./configure --prefix=/Users/mitsuru/.rbenv/versions/2.1.1
 % make
 % make test
 % make install
# 一部省略
installing default sizeof libraries
compiling readline.c
readline.c:1775:37: error: use of undeclared identifier 'username_completion_function'; did you mean
      'rl_username_completion_function'?
                                    rl_username_completion_function);
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    rl_username_completion_function
readline.c:76:42: note: expanded from macro 'rl_username_completion_function'
# define rl_username_completion_function username_completion_function
                                         ^
/usr/local/include/readline/readline.h:457:14: note: 'rl_username_completion_function' declared here
extern char *rl_username_completion_function PARAMS((const char *, int));
             ^
readline.c:1977:26: warning: 'Function' is deprecated [-Wdeprecated-declarations]
    rl_pre_input_hook = (Function *)readline_pre_input_hook;
                         ^
/usr/local/include/readline/rltypedefs.h:35:13: note: 'Function' has been explicitly marked deprecated here
typedef int Function () __attribute__ ((deprecated));
            ^
1 warning and 1 error generated.
make[2]: *** [readline.o] Error 1
make[1]: *** [ext/readline/all] Error 2
make: *** [build-ext] Error 2

またインストールに失敗しました。rl_username_completion_functionでググっても全然情報がありません。そこでreallineで調べていて、これに関する何かが足りないのかなと思いました。とりあえずbrewで入れてみようと思い、先にdoctorで問題がないかチェック。そうすると、readlineの問題が出ていました。指示されたとおりにリンクを外すコマンドを実行。そうするとmake installが成功しました!ちなみに、brew doctorでXQuartzを入れろという警告もありましたので、これもダウンロードしてインストールしました。今回の問題には関係はないかと思いますが挙げておきます。

 % brew doctor
Warning: Some keg-only formula are linked into the Cellar.
Linking a keg-only formula, such as gettext, into the cellar with
`brew link <formula>` will cause other formulae to detect them during
the `./configure` step. This may cause problems when compiling those
other formulae.

Binaries provided by keg-only formulae may override system binaries
with other strange results.

You may wish to `brew unlink` these brews:

    openssl
    readline
 % brew unlink openssl
 % brew unlink readline

# 再インストール
 % rm -rf /Users/mitsuru/.rbenv/sources/2.1.1/
 % rbenv install -k 2.1.1
 % cd /Users/mitsuru/.rbenv/sources/2.1.1/ruby-2.1.1
 % ./configure --prefix=/Users/mitsuru/.rbenv/versions/2.1.1
 % make
 % make test
 % make install

# 確認
 % rbenv version
\* 2.1.1 (set by /Users/mitsuru/Desktop/work/rails-4-1-rspec-3-0/.ruby-version)
  2.1.3
  2.2.2
5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?