LoginSignup
10
10

More than 5 years have passed since last update.

まっさらな OS X Mavericks に rbenv で ruby を入れて、bundler を実行するまで

Posted at

rbenv のインストール

$ brew install rbenv

インストールメッセージにしたがって、.zshrc に追記

if which rbenv > /dev/null; then eval "$(rbenv init - zsh)"; fi

ruby-build のインストール

rbenv は、切り替えを提供するのみで、ruby のビルドは自前でやる必要がある
ruby-build は、その ruby のビルドをサポートしてくれる

$ brew install ruby-build

rbenv の基本操作

$ rbenv install --list          # インストール可能な一覧
$ rbenv install ${バージョン}   # インストール
$ rbenv uninstall ${バージョン} # アンインストール
$ rbenv versions  # インストールされているバージョン一覧
$ rbenv global ${バージョン}    # 特定のバージョンを環境全体のデフォルトにする
$ rbenv local ${バージョン}    # 特定のバージョンをカレントディレクトリ以下でデフォルトにする

rbenv local を実行すると、.rbenv-version が生成される
中身は単にバージョンが書かれているだけのテキストファイル

2.0 系のビルドでエラー

$ rbenv install 2.0.0-p247

Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
Installing yaml-0.1.6...
Installed yaml-0.1.6 to /Users/kasei_san/.rbenv/versions/2.0.0-p247

Downloading ruby-2.0.0-p247.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/c351450a0bed670e0f5ca07da3458a5b
Installing ruby-2.0.0-p247...

BUILD FAILED

Inspect or clean up the working tree at /var/folders/47/0yfz3cbd59j_jkyny3kggc8r0000gn/T/ruby-build.20140422121315.3760
Results logged to /var/folders/47/0yfz3cbd59j_jkyny3kggc8r0000gn/T/ruby-build.20140422121315.3760.log

Last 10 log lines:
1 warning generated.
linking shared-object date_core.bundle
compiling ossl_x509req.c
compiling ossl_x509revoked.c
1 warning generated.
compiling ossl_x509store.c
installing default openssl libraries
linking shared-object openssl.bundle
linking shared-object ripper.bundle
make: *** [build-ext] Error 2

readline のバージョンが、6.2.3 だとエラーが発生

MacでRuby 2.x.xがインストールできないバグ (homebrew + rbenv) - Qiita

readline を更新

$ brew upgrade readline

1.8 系のビルドでエラー

$ rbenv install 1.8.7-p174
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1

ERROR: This package must be compiled with GCC, but ruby-build couldn't
find a suitable `gcc` executable on your system. Please install GCC
and try again.

DETAILS: Apple no longer includes the official GCC compiler with Xcode
as of version 4.2. Instead, the `gcc` executable is a symlink to
`llvm-gcc`, a modified version of GCC which outputs LLVM bytecode.

For most programs the `llvm-gcc` compiler works fine. However,
versions of Ruby older than 1.9.3-p125 are incompatible with
`llvm-gcc`. To build older versions of Ruby you must have the official
GCC compiler installed on your system.

TO FIX THE PROBLEM: Install Homebrew's apple-gcc42 package with this
command: brew tap homebrew/dupes ; brew install apple-gcc42

You will need to install the official GCC compiler to build older
versions of Ruby even if you have installed Apple's Command Line Tools
for Xcode package. The Command Line Tools for Xcode package only
includes `llvm-gcc`.

BUILD FAILED

上記の説明通りに、gcc をインストール

$ brew tap homebrew/dupes
$ brew install apple-gcc42

Mac(Mavericks)にRuby1.8.7を入れようとしたら大変だった話 - Qiita

ruby-build にないバージョンを入れたい

brew で、ruby-build を入れた場合、
/usr/local/share/ruby-build にバージョン毎のインストール方法が書かれたテキストファイルがあるので、そこにファイルを追加する

中身はこんな感じ

$ cat /usr/local/share/ruby-build/1.8.6-p383                                                                  (git)-[master]
require_gcc
install_package "ruby-1.8.6-p383" "http://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p383.tar.gz#4f49544d4a4d0d34e9d86c41e853db2e" auto_tcltk standard
install_package "rubygems-1.3.7" "http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz#e85cfadd025ff6ab689375adbf344bbe" ruby

gemファイルの管理はどうするの?

rbenv は、gemファイルを管理する機能は無くて、基本的に bundler 任せらしい
もし、rvm の gemset 的なものが欲しかったら、rbenv gemset を導入すれば良い

bunlder のインストール

$ gem install bundler

bundle コマンドの実行でエラー!!

コマンド付きの gem をインストールしたら、それを再読込するために rbenv rehash をする

$ bundle install --path vendor/bundle

zsh: command not found: bundle

$ rbenv rehash
$ bundle install --path vendor/bundle
... 正しく動作 ...
10
10
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
10
10