前人未踏の領域へ Androidアプリ開発編

Androidアプリ開発に関する調査メモ置き場。古い記事にはアプリ以外も含まれます。

Mac OS Xに最新バージョンのRubyをインストールする

参考: http://www.atmarkit.co.jp/ait/articles/1402/27/news042_2.html

何カ所かつまづいたのでメモ。

  1. homebrewのインストール
  2. RVMのインストール
  3. Rubyのインストール
  4. Rubyバージョンの確認

1. Homebrewのインストール

http://brew.sh/index_ja.html

1-1. インストール
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
1-2. 最新バージョンにする
$ brew -v
Homebrew 0.9.4
$ sudo brew update

失敗するケース

$ sudo brew update
error: The following untracked working tree files would be overwritten by merge:
	Library/Formula/haxe.rb
	Library/Formula/log4shib.rb
	Library/Formula/opensaml.rb
	Library/Formula/osm2pgsql.rb
	Library/Formula/platypus.rb
	Library/Formula/rats.rb
	Library/Formula/spim.rb
	Library/Formula/xml-security-c.rb
	Library/Formula/xml-tooling-c.rb
Please move or remove them before you can merge.
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master

解決方法
参考:http://qiita.com/laprasDrum/items/59092e96608dd106be63

$ cd /usr/local
$ sudo git fetch origin
sudo git fetch origin
remote: Counting objects: 153, done.
remote: Compressing objects: 100% (80/80), done.
remote: Total 153 (delta 55), reused 147 (delta 52)
Receiving objects: 100% (153/153), 45.53 KiB | 0 bytes/s, done.
Resolving deltas: 100% (55/55), done.
From https://github.com/mxcl/homebrew
   3b16755..6305d2d  gh-pages   -> origin/gh-pages
   7c85b33..32a3498  go         -> origin/go
$sudo git reset --hard origin/master
HEAD is now at d8d5cb5 play 2.2.2
$ sudo brew update
Already up-to-date.
$ brew -v
Homebrew 0.9.5

2. RVM のインストール

http://rvm.io/

$ curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz

Installing RVM to ~/.rvm/
    Adding rvm PATH line to ~/.profile ~/.bashrc ~/.zshrc.
    Adding rvm loading line to ~/.bash_profile /~/.zlogin.
Installation of RVM in ~/.rvm/ is almost complete:

  * To start using RVM you need to run `source ~/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: http://rvm.io/help and https://twitter.com/rvm_io
$ source ~/.bash_profile

rvm関連のスクリプトを読み込む

source ~/.rvm/scripts/rvm

警告の出るケース

  * WARNING: You have '~/.profile' file, you might want to load it,
    to do that add the following line to '~/.bash_profile':
      source ~/.profile

解決方法

$ echo 'source ~/.profile' >> ~/.bash_profile
$ source ~/.bash_profile

3. Rubyのインストール

3-1. 最新バージョンの確認
$ rvm list known ruby
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p374]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p320]
[ruby-]1.9.3[-p545]
[ruby-]2.0.0-p353
[ruby-]2.0.0[-p451]
[ruby-]2.1.1
[ruby-]2.1-head
ruby-head
3-2. インストール

アウトプットは長いので省略。

$ sudo rvm install ruby-2.1.1 --default

上記で失敗する場合は以下をお試しください。

$ rvm install 2.2
3-3. 確認

インストールしただけでは切り替わらない。

$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

4. Rubyバージョンの切り替え

4-1. 一覧をチェック
$ rvm list
rvm rubies

=* ruby-2.1.1 [ x86_64 ]

# => - current
# =* - current && default
#  * - default
4-2. 切り替え
$ rvm use 2.1.1
Using ~/.rvm/gems/ruby-2.1.1
4-3. 確認
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]

お疲れ様でした!