DRY

Web関連の技術の事、食事/お酒の事、旅行の事など

Mountain Lion に Ruby 1.9.3 & Rails 3.2.8 をインストールした

OS X Mountain Lion に Homebrew + rbenv で Ruby 1.9.3 と Rails 3.2.8 をインストールしたので、そのメモを残します。

とりあえず主に参考にさせて頂いたサイトはこちらですnoanoa 日々の日記 : OS X Mountain Lion に Homebrew + rbenv で Ruby 1.9.3 をインストールした

ただ、微妙にエラーの感じが違ったりしたので、自分の分として記載しておきます。

私の環境にはXcode4.5.2が既に入ってますが、何かCommand Line Toolsを入れないとwarningが出たのでとりあえず入れます。

1.Command Line Tools をインストール
 Xcode まずインストールして、Xcode のメニュー > Preferences からダウンロードしてインストールする。

※Command Line Toolsの他のインストール方法は多くのサイトに載っていますので参照下さい。


2. Homebrewのインストール


$ /usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
curl: (22) The requested URL returned error: 404
幾つかのサイトにあるコマンドをコピーしたのですが、404エラーが出るのでRedirecting...で直接確認したら、下記のコマンドだったので、貼り直して無事開始

$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

  • e:67: warning: Insecure world writable dir /Users/nagashima/Develop in PATH, mode 040757
  • e:88: warning: Insecure world writable dir /Users/nagashima/Develop in PATH, mode 040757

==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press ENTER to continue or any other key to abort

  • e:34: warning: Insecure world writable dir /Users/nagashima/Develop in PATH, mode 040757

==> Downloading and Installing Homebrew...
remote: Counting objects: 89578, done.
remote: Compressing objects: 100% (41611/41611), done.
remote: Total 89578 (delta 62414), reused 71609 (delta 47125)
Receiving objects: 100% (89578/89578), 12.92 MiB | 2.44 MiB/s, done.
Resolving deltas: 100% (62414/62414), done.
From https://github.com/mxcl/homebrew
* [new branch] master -> origin/master
Checking out files: 100% (2489/2489), done.
HEAD is now at 2e65c80 elinks 0.12pre6
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help

# まずはbrew doctorをすべしとの指示なので


$ brew doctor
Warning: You have Macports or Fink installed.
This can cause trouble. You don't have to uninstall them, but you may like to
try temporarily moving them away, eg.

sudo mv /opt/local ~/macports
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
/usr/local/lib/libntfs-3g.76.dylib /usr/local/lib/libntfs.9.0.0.dylib /usr/local/lib/libpng15.15.dylib /usr/local/lib/librpm-5.0.dylib /usr/local/lib/librpmbuild-5.0.dylib /usr/local/lib/librpmconstant-5.0.dylib /usr/local/lib/librpmdb-5.0.dylib /usr/local/lib/librpmio-5.0.dylib /usr/local/lib/librpmmisc-5.0.dylib /usr/local/lib/libublio.1.dylib /usr/local/lib/libz.1.2.7.dylib
Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .la files:
/usr/local/lib/libntfs-3g.la /usr/local/lib/libntfs.la /usr/local/lib/libpng15.la /usr/local/lib/libublio.la
Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .pc files:
/usr/local/lib/pkgconfig/fuse.pc /usr/local/lib/pkgconfig/libntfs-3g.pc /usr/local/lib/pkgconfig/libpng15.pc /usr/local/lib/pkgconfig/libublio.pc /usr/local/lib/pkgconfig/rpm.pc /usr/local/lib/pkgconfig/zlib.pc
Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
/usr/local/lib/libntfs-3g.a /usr/local/lib/libntfs.a /usr/local/lib/libpng15.a /usr/local/lib/libublio.a /usr/local/lib/libz.a
Warning: You have a non-Homebrew 'pkg-config' in your PATH:
/opt/local/bin/pkg-config

`./configure` may have problems finding brew-installed packages using
this other pkg-config.
exit 1

多数warningが出ました。

上から順に対応方法は
#1 指示されたコマンドの通りに


$ sudo mv /opt/local ~/macports
Password:
#2 該当ファイルの削除

rm -fr /usr/local/lib/libntfs-3g.76.dylib
rm -fr /usr/local/lib/libntfs.9.0.0.dylib
rm -fr /usr/local/lib/libpng15.15.dylib
rm -fr /usr/local/lib/librpm-5.0.dylib
rm -fr /usr/local/lib/librpmbuild-5.0.dylib
rm -fr /usr/local/lib/librpmconstant-5.0.dylib
rm -fr /usr/local/lib/librpmdb-5.0.dylib
rm -fr /usr/local/lib/librpmio-5.0.dylib
rm -fr /usr/local/lib/librpmmisc-5.0.dylib
rm -fr /usr/local/lib/libublio.1.dylib
rm -fr /usr/local/lib/libz.1.2.7.dylib
#3 該当ファイルの削除

rm -fr /usr/local/lib/libntfs-3g.la
rm -fr /usr/local/lib/libntfs.la
rm -fr /usr/local/lib/libpng15.la
rm -fr /usr/local/lib/libublio.la
#4 該当ファイルの削除

rm -fr /usr/local/lib/libntfs-3g.a
rm -fr /usr/local/lib/libntfs.a
rm -fr /usr/local/lib/libpng15.a
rm -fr /usr/local/lib/libublio.a
rm -fr /usr/local/lib/libz.a
#5 Monoについて確認
masahiro-yanai: macports更新とhomebrewインストールによるとMonoが悪さをしているようで、私の環境にもMonoが入っているのでスクリプトを試してみる

実際のスクリプトMono:OSX - Monoに記載されている


#!/bin/sh -x

#This script removes Mono from an OS X System. It must be run as root

rm -r /Library/Frameworks/Mono.framework

rm -r /Library/Receipts/MonoFramework-*

for dir in /usr/bin /usr/share/man/man1 /usr/share/man/man3 /usr/share/man/man5; do
(cd ${dir};
for i in `ls -al | grep /Library/Frameworks/Mono.framework/ | awk '{print $9}'`; do
rm ${i}
done);
done

#でこのスクリプトを実行

sudo vi /bin/uninstall_mono.sh
sudo chmod 755 /bin/uninstall_mono.sh
sudo /bin/uninstall_mono.sh
#再度doctorの診断を

$ brew doctor
Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .pc files:
/usr/local/lib/pkgconfig/fuse.pc /usr/local/lib/pkgconfig/libntfs-3g.pc /usr/local/lib/pkgconfig/libpng15.pc /usr/local/lib/pkgconfig/libublio.pc /usr/local/lib/pkgconfig/rpm.pc /usr/local/lib/pkgconfig/zlib.pc
exit 1

#再び該当ファイルの削除

rm -fr /usr/local/lib/pkgconfig/fuse.pc
rm -fr /usr/local/lib/pkgconfig/libntfs-3g.pc
rm -fr /usr/local/lib/pkgconfig/libpng15.pc
rm -fr /usr/local/lib/pkgconfig/libublio.pc
rm -fr /usr/local/lib/pkgconfig/rpm.pc
rm -fr /usr/local/lib/pkgconfig/zlib.pc

$ brew doctor
Your system is raring to brew.
#これで診断はすべて問題なくなったので、念のためupdateも確認

$ brew update
Already up-to-date.

3.rbenv と ruby-buildのインストール


$ brew install rbenv
$ brew install ruby-build
==> Downloading https://github.com/sstephenson/rbenv/tarball/v0.3.0
Already downloaded: /Library/Caches/Homebrew/rbenv-0.3.0.tgz
Warning: The cleaning step did not complete successfully
Still, the installation was successful, so we will link it into your prefix
==> Caveats
To enable shims and autocompletion add to your profile:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

To use Homebrew's directories rather than ~/.rbenv add to your profile:
export RBENV_ROOT=/usr/local/opt/rbenv
Warning: This keg was marked linked already, continuing anyway
==> Summary
/usr/local/Cellar/rbenv/0.3.0: 32 files, 168K, built in 2 seconds

#rbenvの設定を.bash_profileに追加する。

$ vi ~/.bash_profile

  1. # Ruby
  2. echo 'eval "$(rbenv init -)"' >> .bash_profile

$ source ~/.bash_profile

#rbenv の設定をいろいろ変えたときは、そのつど反映させるためには rehash が必要だとの事なので
$ rbenv rehash

4.ruby をインストールreadline と OpenSSL のライブラリをインストールしておく必要があるとの事なので


$ brew install readline
==> Downloading http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz
######################################################################## 100.0%
==> Patching
patching file callback.c
patching file input.c
patching file patchlevel
patching file support/shobj-conf
patching file vi_mode.c
==> ./configure --prefix=/usr/local/Cellar/readline/6.2.4 --mandir=/usr/local/Cellar/readline/6.2.4/share/
brew link readline

brew install openssl
brew link openssl
^[[A^[[B==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/readline/lib
CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
/usr/local/Cellar/readline/6.2.4: 31 files, 1.8M, built in 42 seconds
$ brew link readline
Linking /usr/local/Cellar/readline/6.2.4... 12 symlinks created
$
$ brew install openssl
==> Downloading http://openssl.org/source/openssl-1.0.1c.tar.gz
######################################################################## 100.0%
==> perl ./Configure --prefix=/usr/local/Cellar/openssl/1.0.1c --openssldir=/usr/local/etc/openssl zlib-dy
==> make
==> make test
==> make install MANDIR=/usr/local/Cellar/openssl/1.0.1c/share/man MANSUFFIX=ssl
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

The OpenSSL provided by OS X is too old for some software.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
/usr/local/Cellar/openssl/1.0.1c: 429 files, 15M, built in 4.9 minutes
$ brew link openssl
Linking /usr/local/Cellar/openssl/1.0.1c... 1139 symlinks created

#インストール可能な Ruby のバージョンを確認


$ rbenv install -l
Available versions:
1.8.6-p383
1.8.6-p420
1.8.7-p249
1.8.7-p302
1.8.7-p334
1.8.7-p352
1.8.7-p357
1.8.7-p358
1.8.7-p370
1.9.1-p378
1.9.2-p180
1.9.2-p290
1.9.2-p318
1.9.2-p320
1.9.3-dev
1.9.3-p0
1.9.3-p125
1.9.3-p194
1.9.3-p286
1.9.3-p327
1.9.3-preview1
1.9.3-rc1
2.0.0-dev
2.0.0-preview1
jruby-1.5.6
jruby-1.6.3
jruby-1.6.4
jruby-1.6.5
jruby-1.6.5.1
jruby-1.6.6
jruby-1.6.7
jruby-1.6.7.2
jruby-1.6.8
jruby-1.7.0
jruby-1.7.0-preview1
jruby-1.7.0-preview2
jruby-1.7.0-rc1
jruby-1.7.0-rc2
maglev-1.0.0
maglev-1.1.0-dev
rbx-1.2.4
rbx-2.0.0-dev
rbx-2.0.0-rc1
ree-1.8.6-2009.06
ree-1.8.7-2009.09
ree-1.8.7-2009.10
ree-1.8.7-2010.01
ree-1.8.7-2010.02
ree-1.8.7-2011.03
ree-1.8.7-2011.12
ree-1.8.7-2012.01
ree-1.8.7-2012.02

#ここで、新しいバージョンの Ruby が表示されないときは、ruby-build を upgrade すると良いとの事
なので念の為実行


$ brew upgrade ruby-build
Error: ruby-build-20121120 already installed

# 更新されるようであればrehash を忘れずに!
rbenv rehash
rbenv instal

the latest and greatest version をインストールすべしとの事みたいなので
「1.9.3-p327」をチョイス


$ rbenv install 1.9.3-p327
Downloading yaml-0.1.4.tar.gz...

Installing yaml-0.1.4...
Installed yaml-0.1.4 to /Users/nagashima/.rbenv/versions/1.9.3-p327

Downloading ruby-1.9.3-p327.tar.gz...

Installing ruby-1.9.3-p327...
Installed ruby-1.9.3-p327 to /Users/nagashima/.rbenv/versions/1.9.3-p327

exit 1

#インストールされているバージョンを確認


$ rbenv versions
1.9.3-p327

5.rails をインストール


$ gem install rails
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.
exit 1
#おいっ!って事なんですが、実は$ gem install rails打った後にとにかく待ちます。
プロンプトが何の反応も無いので、止まってるように見えますが動いてます。
(事実私も何回か、Crtl+Cしちゃいました。。。)



$ sudo gem install rails
Password:

# 約10分後 ------>

Building native extensions. This could take a while...
Depending on your version of ruby, you may need to install ruby rdoc/ri data:<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
Successfully installed i18n-0.6.1
Successfully installed multi_json-1.3.7
Successfully installed activesupport-3.2.9
Successfully installed builder-3.0.4
Successfully installed activemodel-3.2.9
Successfully installed rack-1.4.1
Successfully installed rack-cache-1.2
Successfully installed rack-test-0.6.2
Successfully installed journey-1.0.4
Successfully installed hike-1.2.1
Successfully installed tilt-1.3.3
Successfully installed sprockets-2.2.1
Successfully installed erubis-2.7.0
Successfully installed actionpack-3.2.9
Successfully installed arel-3.0.2
Successfully installed tzinfo-0.3.35
Successfully installed activerecord-3.2.9
Successfully installed activeresource-3.2.9
Successfully installed mime-types-1.19
Successfully installed polyglot-0.3.3
Successfully installed treetop-1.4.12
Successfully installed mail-2.4.4
Successfully installed actionmailer-3.2.9
Successfully installed rake-10.0.2
Successfully installed rack-ssl-1.3.2
Successfully installed thor-0.16.0
Successfully installed json-1.7.5
Successfully installed rdoc-3.12
Successfully installed railties-3.2.9
Successfully installed bundler-1.2.2
Successfully installed rails-3.2.9
31 gems installed

#一応確認


$ rails -v
Rails 3.2.9
という事で無事すべてインストール出来たようです。