読者です 読者をやめる 読者になる 読者になる

mountain lion でrvm使ってruby1.9.3インストールしようとしてはまった。さらにbundle使ってたらはまった。

MacのMountain Lionでrvmをインストールして、ruby1.9.3を入れようと思ったらハマったのでメモ。
ちなみにXcodeのバージョンは4.5.2で、Command Line Toolsはインストール済み。


rvm install 1.9.3とやると以下の文章がでてきた。

Ruby (and needed base gems) for your selection will be installed shortly.
Before it happens, please read and execute the instructions below.
Please use a separate terminal to execute any additional commands.

Notes for Mac OS X 10.8.2, Xcode 4.5.2.

For JRuby: Install the JDK. See http://developer.apple.com/java/download/ # Current Java version "1.6.0_26"
For IronRuby: Install Mono >= 2.6
For Ruby 1.9.3: Install libksba # If using Homebrew, 'brew install libksba'
For Opal: Install Nodejs with NPM. See http://nodejs.org/download/

To use an RVM installed Ruby as default, instead of the system ruby:

rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7

And reopen your terminal windows.

Xcode and gcc:

Right now Ruby requires gcc to compile, but Xcode 4.2 and later no longer ship with gcc. Instead they ship with llvm-gcc (to which gcc is a symlink) and clang, neither of which are supported for building Ruby. Xcode 4.1 was the last version to ship gcc, which was /usr/bin/gcc-4.2.

Xcode 4.1 and earlier:

  • Ruby will build fine.

Xcode 4.2 and later (including Command Line Tools for Xcode):

  • If you have gcc-4.2 (and friends) from an earlier Xcode version, Ruby will build fine.
  • If you don't have gcc-4.2, you have two options to get it:

* Install apple-gcc42 from Homebrew
* Install osx-gcc-installer

Homebrew:

If you are using Homebrew, you can install the apple-gcc42 and required libraries from homebrew/dupes:

brew update
brew tap homebrew/dupes
brew install autoconf automake apple-gcc42
rvm pkg install openssl

Xcode 4.2+ install or/and Command Line Tools for Xcode is required to provide make and other tools.

osx-gcc-installer:

If you don't use Homebrew, you can download and install osx-gcc-installer: https://github.com/kennethreitz/osx-gcc-installer.

Warning: Installing osx-gcc-installer on top of a recent Xcode is known to cause problems, so you must uninstall Xcode before installing osx-gcc-installer. Afterwards you may install Xcode 4.2+ or Command Line Tools for Xcode if you desire.

** NOTE: Currently, Node.js is having issues building with osx-gcc-installer. The only fix is to install Xcode over osx-gcc-installer.

Press 'q' to continue.

libksba のインストール

普通に、brew install libksba とやるとパーミッションのエラーが出たので、sudoでやろうとしたらhomebrewはsudoが使えない。
なので、mkdir /usr/local/opt して、一時的にパーミッションを777にしたらうまくいった。
libksbaとlibgpg-errorが入った。

apple-gcc42 のインストール

手順通り

ruby 1.9.3のインストール

[sagaraya: manga_log] 543 $ rvm install 1.9.3
https://rvm.io/binaries/osx/10.8/x86_64/ruby-1.9.3-p327.tar.bz2 - #configure
ruby-1.9.3-p327 - #download
ruby-1.9.3-p327 - #extract
ruby-1.9.3-p327 - #validate
ruby-1.9.3-p327 - #setup
sed: RE error: illegal byte sequence
Saving wrappers to '/Users/sagaraya/.rvm/bin'.
ruby-1.9.3-p327 - #importing default gemsets (/Users/sagaraya/.rvm/gemsets/), this may take time ...

[sagaraya: manga_log] 544 $ rvm list

rvm rubies

=* /Users/sagaraya/.rvm/scripts/list: line 321: /Users/sagaraya/.rvm/rubies/ruby-1.9.3-p327/config: No such file or directory
ruby-1.9.3-p327 [ ]

# => - current
# =* - current && default
# * - default

うまくいかず。
これはrvmのバグらしく、(参考:http://stackoverflow.com/questions/13224930/rvm-config-no-such-file-or-directory

rvm get stable
rvm get head
rvm reinstall 1.9.3

したらうまくはいった!

ruby 1.9.3をデフォルトで使うものに設定

[sagaraya: manga_log] 549 $ rvm use 1.9.3 --default
Using /Users/sagaraya/.rvm/gems/ruby-1.9.3-p327
[sagaraya: manga_log] 550 $ ruby -v
ruby 1.9.3p327 (2012-11-10) [x86_64-darwin12.2.0]

以下の1.8.7を1.9.3に置き換えて設定

rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7

bundle

bundle exec rackupとやったら、

Library not loaded: @executable_path/../lib/libruby.1.9.1.dylib (LoadError)

というエラーがでて色々調べたけど結局解決できず、

いったん

rm -rf vendor/bundle/ruby
bundle install --path vendor/bundle

したらうまくいった!