The HIRO Says

If you smell what The HIRO is cooking!!!

Ruby の開発環境を MacBook Air に構築してみた

自宅の PC を Windows から MacBook Air に変えたので、Ruby の環境を構築してみました。

0. Prerequisite

OS Mac OS X 10.8.3
CPU 2GHz Intel Core i7
Memory 8GB 1600 MHz DDR3
入れる Ruby 2.0.0-p0

1. Homebrew

色々と調べてみたら、Mac では Homebrew というパッケージ管理ツールが便利ということだったので、まずはこれをインストール。apt-get や RubyGemsMac 版と考えてよさそう。
【参考】http://tools4hack.santalab.me/howto-mountainlion-install-homebrew.html

1.1. JRE

1.6 系が好き&Java でも開発するので、JDK 1.6.0_43 をインストール。

1.2. Xcode Command Line Tools
  1. まず XcodeApp Store で入手。これで iOS アプリも開発できるぞ!
  2. Xcode を起動し、Xcode -> Preferences で Command Line Tools をインストール。
1.3. Homebrew

preinstall されていた Ruby 1.8.7 を使って、Homebrew をインストール。

ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
==> The following directories will be made group writable:
/usr/local/.
/usr/local/bin
/usr/local/include
/usr/local/lib
==> The following directories will have their group set to admin:
/usr/local/.
/usr/local/bin
/usr/local/include
/usr/local/lib

Press ENTER to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/bin /usr/local/include /usr/local/lib

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/. /usr/local/bin /usr/local/include /usr/local/lib
==> Downloading and Installing Homebrew...
remote: Counting objects: 109252, done.
remote: Compressing objects: 100% (30140/30140), done.
remote: Total 109252 (delta 78684), reused 106988 (delta 78183)
Receiving objects: 100% (109252/109252), 13.46 MiB | 1.53 MiB/s, done.
Resolving deltas: 100% (78684/78684), done.
From https://github.com/mxcl/homebrew
 * [new branch]      master     -> origin/master
Checking out files: 100% (2644/2644), done.
HEAD is now at cb72b5f gmp: remove bottle.
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help

以下はお決まりのコマンドらしい。内容は後日調査。

brew doctor
Warning: Your Xcode (4.6.1) is outdated
Please install Xcode 4.6.2.

brew update
Already up-to-date.

brew -v
Homebrew 0.9.4

2.Ruby

主に ここ を参考にトライ。

2.1.ruby-build
brew install --HEAD ruby-build
Warning: Your Xcode (4.6.1) is outdated
Please install Xcode 4.6.2.
==> Installing ruby-build dependency: autoconf
==> Downloading http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/autoconf/2.69
==> make install
🍺  /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M, built in 19 seconds
==> Installing ruby-build dependency: pkg-config
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-
######################################################################## 100.0%
==> Pouring pkg-config-0.28.mountain_lion.bottle.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.28: 10 files, 636K
==> Installing ruby-build
==> Cloning https://github.com/sstephenson/ruby-build.git
Cloning into '/Library/Caches/Homebrew/ruby-build--git'...
remote: Counting objects: 109, done.
remote: Compressing objects: 100% (85/85), done.
remote: Total 109 (delta 42), reused 77 (delta 17)
Receiving objects: 100% (109/109), 30.89 KiB, done.
Resolving deltas: 100% (42/42), done.
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/HEAD: 75 files, 332K, built in 5 seconds
2.2.rbenv
brew install rbenv
Warning: Your Xcode (4.6.1) is outdated
Please install Xcode 4.6.2.
==> Downloading https://github.com/sstephenson/rbenv/archive/v0.4.0.tar.gz
######################################################################## 100.0%
==> Caveats
To use Homebrew's directories rather than ~/.rbenv add to your profile:
  export RBENV_ROOT=/usr/local/var/rbenv

To enable shims and autocompletion add to your profile:
  if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
==> Summary
🍺  /usr/local/Cellar/rbenv/0.4.0: 31 files, 152K, built in 2 seconds
2.3.Ruby

rbenv install -l

  • > 2.0.0-p0 の存在を確認
rbenv install 2.0.0-p0
Downloading openssl-1.0.1e.tar.gz...
Installing openssl-1.0.1e...
Installed openssl-1.0.1e to /Users/hageyahhoo/.rbenv/versions/2.0.0-p0

Downloading ruby-2.0.0-p0.tar.gz...
Installing ruby-2.0.0-p0...

Installed ruby-2.0.0-p0 to /Users/hageyahhoo/.rbenv/versions/2.0.0-p0

変更を反映。
rbenv rehash

1.8.7 と 2.0.0-p0 が共存しているので、2.0.0-p0 を使うよう設定。

  1. rbenv global 2.0.0-p0
  2. ターミナルを再起動。

ruby -v で 2.0.0-p0 が出るところまで確認。