ラベル rbenv の投稿を表示しています。 すべての投稿を表示
ラベル rbenv の投稿を表示しています。 すべての投稿を表示

2016年2月26日金曜日

itamaeでrbenv入れるのにはまった恥ずかしい話

ec2でrbenv入れるのにitamaeで入れようとしてたのですが、
rbenvのインストール手順を普通になぞっていったら地味にはまってしまいました。

最初に書いたレシピはこんな感じ
rbenv/default.rb
%w(
  git
  gcc-c++
  glibc-headers
  openssl-devel
  readline
  libyaml-devel
  readline-devel
  zlib
  zlib-devel
  libffi-devel
  libxml2
  libxslt
  libxml2-devel
  libxslt-devel
  sqlite-devel
  mysql-devel
  patch
).each do |pkg|
  package "#{pkg}" do
    action :install
  end
end

git '/usr/local/rbenv' do
  repository 'https://github.com/sstephenson/rbenv.git'
end

directory "/urs/local/rbenv/plugins" do
  action :create
end

git '/usr/local/rbenv/plugins/ruby-build' do
  repository 'https://github.com/sstephenson/ruby-build.git'
end

remote_file "/etc/profile.d/rbenv.sh" do
  action :create
  source "files/etc/profile.d/rbenv.sh"
  owner 'root'
  group 'root'
  mode '644'
end

execute 'install ruby' do
  command("source /etc/profile.d/rbenv.sh; rbenv install 2.3.0")
  command("source /etc/profile.d/rbenv.sh; rbenv global 2.3.0; rbenv rehash")
end

実行してみるとこんな感じ
$ bundle exec itamae ssh -i pem/test.pem -h 172.31.21.186 roles/test.rb
 INFO : Starting Itamae...
 INFO : Recipe: /home/ec2-user/deploy/xxx/roles/test.rb
 INFO :   Recipe: /home/ec2-user/deploy/xxx/cookbooks/rbenv/default.rb
 INFO :     package[git] installed will change from 'false' to 'true'
 INFO :     package[gcc-c++] installed will change from 'false' to 'true'
 INFO :     package[openssl-devel] installed will change from 'false' to 'true'
 INFO :     package[libyaml-devel] installed will change from 'false' to 'true'
 INFO :     package[readline-devel] installed will change from 'false' to 'true'
 INFO :     package[libffi-devel] installed will change from 'false' to 'true'
 INFO :     package[libxml2-devel] installed will change from 'false' to 'true'
 INFO :     package[libxslt-devel] installed will change from 'false' to 'true'
 INFO :     package[sqlite-devel] installed will change from 'false' to 'true'
 INFO :     package[mysql-devel] installed will change from 'false' to 'true'
 INFO :     package[patch] installed will change from 'false' to 'true'
 INFO :     git[/usr/local/rbenv] exist will change from 'false' to 'true'
 INFO :     directory[/urs/local/rbenv/plugins] exist will change from 'false' to 'true'
 INFO :     git[/usr/local/rbenv/plugins/ruby-build] exist will change from 'false' to 'true'
 INFO :     remote_file[/etc/profile.d/rbenv.sh] exist will change from 'false' to 'true'
 INFO :     remote_file[/etc/profile.d/rbenv.sh] mode will be '0644'
 INFO :     remote_file[/etc/profile.d/rbenv.sh] owner will be 'root'
 INFO :     remote_file[/etc/profile.d/rbenv.sh] group will be 'root'
 INFO :     diff:
 INFO :     --- /dev/null 2016-02-25 02:37:28.211836042 +0000
 INFO :     +++ /tmp/itamae_tmp/1456368153.1309056 2016-02-25 02:42:33.144609603 +0000
 INFO :     @@ -0,0 +1,3 @@
 INFO :     +export RBENV_ROOT=/usr/local/rbenv
 INFO :     +export PATH="$RBENV_ROOT/bin:$PATH"
 INFO :     +eval "$(rbenv init -)"
 INFO :     execute[install ruby] executed will change from 'false' to 'true'

正常に終わったように見えてるが、rubyのバージョンが変わってない。。。
$ruby -v
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]

レシピのrubyインストール部分を以下のようにコマンドを分割する形に修正
rbenv/default.rb
execute 'install ruby' do
  command("source /etc/profile.d/rbenv.sh; rbenv install 2.3.0")
end

execute 'set ruby global' do
  command("source /etc/profile.d/rbenv.sh; rbenv global 2.3.0; rbenv rehash")
end

再度実行してみる
$ bundle exec itamae ssh -i pem/test.pem -h 172.31.21.186 roles/test.rb
 INFO : Starting Itamae...
 INFO : Recipe: /home/ec2-user/deploy/xxx/roles/test.rb
 INFO :   Recipe: /home/ec2-user/deploy/xxx/cookbooks/rbenv/default.rb
 INFO :     execute[install ruby] executed will change from 'false' to 'true'
 INFO :     execute[set ruby global] executed will change from 'false' to 'true'

ちゃんとrubyのバージョンがrbenvで入れたものに変わりました
$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]


参考URL
http://qiita.com/fukuiretu/items/337e6ae15c1f01e93ec3

2015年7月13日月曜日

awsのec2インスタンス作成時にruby2.2.2をインストールするユーザーデータ

完全にメモですが、awsでec2インスタンス作るときに、
ruby2.2.2をrbenvで入れてある状態にするユーザーデータです。

#!/bin/bash
yum update -y
yum install -y git
yum install -y gcc-c++ glibc-headers openssl-devel readline libyaml-devel readline-devel zlib zlib-devel libffi-devel libxml2 libxslt libxml2-devel libxslt-devel sqlite-devel mysql-devel
yum install -y patch
 
cd /usr/local
git clone https://github.com/sstephenson/rbenv.git
mkdir -p /usr/local/rbenv/plugins
cd /usr/local/rbenv/plugins
git clone https://github.com/sstephenson/ruby-build.git
 
cat << EOF >> /etc/profile.d/rbenv.sh
export RBENV_ROOT=/usr/local/rbenv
export PATH="\$RBENV_ROOT/bin:\$PATH"
eval "\$(rbenv init -)"
EOF
 
source /etc/profile.d/rbenv.sh
rbenv install -f 2.2.2
rbenv rehash
rbenv global 2.2.2
rbenv version
最後にrbenv versionを入れてないと、最初にログインした時のruby -vが2.2.2にならなかった

参考URL
http://hivecolor.com/id/129

2014年12月27日土曜日

CentOS6.5にruby2.2.0を入れてみた

CentOS6.5にruby2.2.0を入れてみました。

rubyのバージョン管理はrbenvとruby-buildでやっています。
そのインストールは別途調べてください。

まずはruby-buildをアップデートします。
アップデート後にインストールできるバージョンを確認すると、2.2.0が追加されています。
# 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.8.7-p371
  1.8.7-p374
  1.8.7-p375
  1.9.1-p378
  1.9.1-p430
  1.9.2-p0
  1.9.2-p180
  1.9.2-p290
  1.9.2-p318
  1.9.2-p320
  1.9.2-p326
  1.9.2-p330
  1.9.3-dev
  1.9.3-preview1
  1.9.3-rc1
  1.9.3-p0
  1.9.3-p125
  1.9.3-p194
  1.9.3-p286
  1.9.3-p327
  1.9.3-p362
  1.9.3-p374
  1.9.3-p385
  1.9.3-p392
  1.9.3-p429
  1.9.3-p448
  1.9.3-p484
  1.9.3-p545
  1.9.3-p547
  1.9.3-p550
  1.9.3-p551
  2.0.0-dev
  2.0.0-preview1
  2.0.0-preview2
  2.0.0-rc1
  2.0.0-rc2
  2.0.0-p0
  2.0.0-p195
  2.0.0-p247
  2.0.0-p353
  2.0.0-p451
  2.0.0-p481
  2.0.0-p576
  2.0.0-p594
  2.0.0-p598
  2.1.0-dev
  2.1.0-preview1
  2.1.0-preview2
  2.1.0-rc1
  2.1.0
  2.1.1
  2.1.2
  2.1.3
  2.1.4
  2.1.5
  2.2.0-dev
  2.2.0-preview1
  2.2.0-preview2
  2.2.0-rc1
  2.2.0
  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-preview1
  jruby-1.7.0-preview2
  jruby-1.7.0-rc1
  jruby-1.7.0-rc2
  jruby-1.7.0
  jruby-1.7.1
  jruby-1.7.2
  jruby-1.7.3
  jruby-1.7.4
  jruby-1.7.5
  jruby-1.7.6
  jruby-1.7.7
  jruby-1.7.8
  jruby-1.7.9
  jruby-1.7.10
  jruby-1.7.11
  jruby-1.7.12
  jruby-1.7.13
  jruby-1.7.14
  jruby-1.7.15
  jruby-1.7.16
  jruby-1.7.16.1
  jruby-1.7.16.2
  jruby-1.7.17
  jruby-1.7.18
  jruby-9.0.0.0-dev
  jruby-9.0.0.0+graal-dev
  jruby-9000-dev
  jruby-9000+graal-dev
  maglev-1.0.0
  maglev-1.1.0-dev
  maglev-2.0.0-dev
  mruby-dev
  mruby-1.0.0
  rbx-1.2.4
  rbx-2.0.0-dev
  rbx-2.0.0-rc1
  rbx-2.0.0
  rbx-2.1.0
  rbx-2.1.1
  rbx-2.2.0
  rbx-2.2.1
  rbx-2.2.2
  rbx-2.2.3
  rbx-2.2.4
  rbx-2.2.5
  rbx-2.2.6
  rbx-2.2.7
  rbx-2.2.9
  rbx-2.2.10
  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
  topaz-dev

早速2.2.0をインストールしてみます。
# rbenv install 2.2.0
Downloading ruby-2.2.0.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/7671e394abfb5d262fbcd3b27a71bf78737c7e9347fa21c39e58b0bb9c4840fc
Installing ruby-2.2.0...
 
BUILD FAILED (CentOS release 6.5 (Final) using ruby-build 20141225-1-g45b75ed)
 
Inspect or clean up the working tree at /tmp/ruby-build.20141226162728.13624
Results logged to /tmp/ruby-build.20141226162728.13624.log
 
Last 10 log lines:
make[3]: ディレクトリ `/tmp/ruby-build.20141226162728.13624/ruby-2.2.0/ext/fiddle/libffi-3.2.1' から出ます
linking shared-object fiddle.so
/usr/bin/ld: ./libffi-3.2.1/.libs/libffi.a(raw_api.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
./libffi-3.2.1/.libs/libffi.a: could not read symbols: Bad value
collect2: ld はステータス 1 で終了しました
make[2]: *** [../../.ext/x86_64-linux/fiddle.so] エラー 1
make[2]: ディレクトリ `/tmp/ruby-build.20141226162728.13624/ruby-2.2.0/ext/fiddle' から出ます
make[1]: *** [ext/fiddle/all] エラー 2
make[1]: ディレクトリ `/tmp/ruby-build.20141226162728.13624/ruby-2.2.0' から出ます
make: *** [build-ext] エラー 2
エラーが出ました。
libffi云々でエラーが出ました。
libffiのインストール状況とリポジトリの情報を調べてみました。
# yum list installed|grep libffi
libffi.x86_64           3.0.5-3.2.el6   @anaconda-CentOS-201311291202.x86_64/6.5

# yum search libffi
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
============================================================================= N/S Matched: libffi =============================================================================
libffi-devel.i686 : Development files for libffi
libffi-devel.x86_64 : Development files for libffi
libffi.i686 : A portable foreign function interface library
libffi.x86_64 : A portable foreign function interface library
 
  Name and summary matches only, use "search all" for everything.
libffi-devel.x86_64を入れてみて、再度2.2.0のインストールを実行すると成功しました。
# rbenv versions
  2.2.0

参考URL
http://qiita.com/MorimotoYasunori@github/items/fb81946fc088b18d6a3a

2014年11月28日金曜日

rbenvの環境でcronでrakeタスクを動かしてはまった

rakeタスクを作って、localでも動いたし、staging環境で手動で動かしても動作したのに、
cronで実行させると動かなくてはまったときの話です。

まずは手動で動かすために以下のようなコマンドを手動で実行しました。
bundle exec rake aaa:bbb
とりあえず動きはしたものの、staging環境の設定で動きませんでした。
調べたところ、RAILS_ENV=stagingをつける必要があるようです。
bundle exec rake aaa:bbb RAILS_ENV=staging
手動で動いたのでcronを以下のように設定しました。
crontab -l
0 * * * * cd /home/xxx/app && bundle exec rake aaa:bbb RAILS_ENV=staging
時間が来てうまく動かなかったので調べたところ、PATHにrbenv/shimsが入ってないようでした。
cronでrbenvのrubyを使うのにはいくつか方法があるようですが、
他の環境や設定に影響を与えない/bin/bash -lc 'コマンド'でやることにしました。
0 * * * * /bin/bash -lc 'cd /home/xxx/app && bundle exec rake aaa:bbb RAILS_ENV=staging'

RAILS_ENVのところは環境別に書きかわるようにしたかったので、
crontabにつらつら書くのではなくてシェルを作って動的に変わるように対応しました。


参考URL
http://pentan.info/ruby/ror/rake_list.html
http://blog.livedoor.jp/sonots/archives/33204053.html

2014年8月22日金曜日

homebrewで入れたrbenvで新しいバージョンのrubyを入れられるようにする

以前Macにrbenvでrubyを入れたのですが、rubyの新しいバージョンが出たので、
それにバージョンアップを行いました。

まずは現在のバージョンを確認
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]

rbenvで入れられるバージョンを確認。
2.1.2が出てるはずなのに表示されないですね。
$ 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.8.7-p371
  1.8.7-p374
  1.8.7-p375
  1.9.1-p378
  1.9.1-p430
  1.9.2-p0
  1.9.2-p180
  1.9.2-p290
  1.9.2-p318
  1.9.2-p320
  1.9.2-p326
  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-p362
  1.9.3-p374
  1.9.3-p385
  1.9.3-p392
  1.9.3-p429
  1.9.3-p448
  1.9.3-p484
  1.9.3-p545
  1.9.3-preview1
  1.9.3-rc1
  2.0.0-dev
  2.0.0-p0
  2.0.0-p195
  2.0.0-p247
  2.0.0-p353
  2.0.0-p451
  2.0.0-preview1
  2.0.0-preview2
  2.0.0-rc1
  2.0.0-rc2
  2.1.0
  2.1.0-dev
  2.1.0-preview1
  2.1.0-preview2
  2.1.0-rc1
  2.1.1
  2.2.0-dev
  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
  jruby-1.7.1
  jruby-1.7.10
  jruby-1.7.11
  jruby-1.7.2
  jruby-1.7.3
  jruby-1.7.4
  jruby-1.7.5
  jruby-1.7.6
  jruby-1.7.7
  jruby-1.7.8
  jruby-1.7.9
  jruby-9000+graal-dev
  jruby-9000-dev
  maglev-1.0.0
  maglev-1.1.0-dev
  maglev-2.0.0-dev
  mruby-1.0.0
  mruby-dev
  rbx-1.2.4
  rbx-2.0.0
  rbx-2.0.0-dev
  rbx-2.0.0-rc1
  rbx-2.1.0
  rbx-2.1.1
  rbx-2.2.0
  rbx-2.2.1
  rbx-2.2.2
  rbx-2.2.3
  rbx-2.2.4
  rbx-2.2.5
  rbx-2.2.6
  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
  topaz-dev

homebrewのruby-buildを確認。
新しいバージョンが出ていました。
$ brew info ruby-build
ruby-build: stable 20140524, HEAD
https://github.com/sstephenson/ruby-build
/usr/local/Cellar/ruby-build/20140408 (114 files, 488K) *
  Built from source
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/ruby-build.rb
==> Dependencies
Recommended: autoconf ✔, pkg-config ✔, openssl ✔
==> Options
--without-autoconf
 Build without autoconf support
--without-openssl
 Build without openssl support
--without-pkg-config
 Build without pkg-config support
--HEAD
 install HEAD version

ruby-buildをアップデートします。
$ brew upgrade ruby-build
==> Upgrading 1 outdated package, with result:
ruby-build 20140524
==> Upgrading ruby-build
==> Downloading https://github.com/sstephenson/ruby-build/archive/v20140524.tar.gz
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/20140524: 119 files, 512K, built in 3 seconds

rbenvで入れられるバージョンを確認します。
2.1.2が表示されるようになりました。
$ 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.8.7-p371
  1.8.7-p374
  1.8.7-p375
  1.9.1-p378
  1.9.1-p430
  1.9.2-p0
  1.9.2-p180
  1.9.2-p290
  1.9.2-p318
  1.9.2-p320
  1.9.2-p326
  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-p362
  1.9.3-p374
  1.9.3-p385
  1.9.3-p392
  1.9.3-p429
  1.9.3-p448
  1.9.3-p484
  1.9.3-p545
  1.9.3-p547
  1.9.3-preview1
  1.9.3-rc1
  2.0.0-dev
  2.0.0-p0
  2.0.0-p195
  2.0.0-p247
  2.0.0-p353
  2.0.0-p451
  2.0.0-p481
  2.0.0-preview1
  2.0.0-preview2
  2.0.0-rc1
  2.0.0-rc2
  2.1.0
  2.1.0-dev
  2.1.0-preview1
  2.1.0-preview2
  2.1.0-rc1
  2.1.1
  2.1.2
  2.2.0-dev
  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
  jruby-1.7.1
  jruby-1.7.10
  jruby-1.7.11
  jruby-1.7.12
  jruby-1.7.2
  jruby-1.7.3
  jruby-1.7.4
  jruby-1.7.5
  jruby-1.7.6
  jruby-1.7.7
  jruby-1.7.8
  jruby-1.7.9
  jruby-9000+graal-dev
  jruby-9000-dev
  maglev-1.0.0
  maglev-1.1.0-dev
  maglev-2.0.0-dev
  mruby-1.0.0
  mruby-dev
  rbx-1.2.4
  rbx-2.0.0
  rbx-2.0.0-dev
  rbx-2.0.0-rc1
  rbx-2.1.0
  rbx-2.1.1
  rbx-2.2.0
  rbx-2.2.1
  rbx-2.2.2
  rbx-2.2.3
  rbx-2.2.4
  rbx-2.2.5
  rbx-2.2.6
  rbx-2.2.7
  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
  topaz-dev

rbenvで2.1.2をインストールします。
$ rbenv install 2.1.2
Downloading ruby-2.1.2.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/f22a6447811a81f3c808d1c2a5ce3b5f5f0955c68c9a749182feb425589e6635
Installing ruby-2.1.2...
Installed ruby-2.1.2 to /Users/xxxx/.rbenv/versions/2.1.2
 
Fetching: bundler-1.6.5.gem (100%)
Successfully installed bundler-1.6.5
Parsing documentation for bundler-1.6.5
Installing ri documentation for bundler-1.6.5
Done installing documentation for bundler after 2 seconds
1 gem installed
 

systemのrubyに2.1.2を登録。
無事にバージョンをあげることができました。
$ rbenv rehash
$ rbenv global 2.1.2
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]

2014年5月8日木曜日

rbenv-default-gemsでruby install時に必要なgemが最初から入ってるようにする

Macにrbenvでrubyを入れたので、次はrbenv-default-gemsを使って、
rubyのバージョンを指定してinstallした時に、必要なgemも一緒に入るようにしてみました。

まずはbrewでrbenv-default-gemsをインストール
$ brew install rbenv-default-gems
==> Downloading https://github.com/sstephenson/rbenv-default-gems/archive/v1.0.0.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/rbenv-default-gems/1.0.0: 4 files, 16K, built in 2 seconds

gem listで今入ってるのを表示
$ gem list
 
*** LOCAL GEMS ***
 
bigdecimal (1.2.4)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
psych (2.0.3)
rake (10.1.0)
rdoc (4.1.0)
test-unit (2.1.1.0)

default-gemsファイルを生成してbundlerと記述。
$ ls -al ~/.rbenv/default-gems
ls: /Users/xxxx/.rbenv/default-gems: No such file or directory
 
$ echo "bundler" >  ~/.rbenv/default-gems
 
$ ls -al ~/.rbenv/default-gems
-rw-r--r--  1 xxxx  xxxx  8  4 11 15:49 /Users/xxxx/.rbenv/default-gems

rbenvでバージョン2.1.1をインストール
$ rbenv install 2.1.1
rbenv: /Users/xxxx/.rbenv/versions/2.1.1 already exists
continue with installation? (y/N) y
Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
Installing yaml-0.1.6...
Installed yaml-0.1.6 to /Users/xxxx/.rbenv/versions/2.1.1
 
Downloading ruby-2.1.1.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/e57fdbb8ed56e70c43f39c79da1654b2
Installing ruby-2.1.1...
Installed ruby-2.1.1 to /Users/xxxx/.rbenv/versions/2.1.1
 
Fetching: bundler-1.6.1.gem (100%)
Successfully installed bundler-1.6.1
Parsing documentation for bundler-1.6.1
Installing ri documentation for bundler-1.6.1
Done installing documentation for bundler after 2 seconds
1 gem installed

gem listを表示すると、bundlerが追加されている。
$ gem list
 
*** LOCAL GEMS ***
 
bigdecimal (1.2.4)
bundler (1.6.1)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
psych (2.0.3)
rake (10.1.0)
rdoc (4.1.0)
test-unit (2.1.1.0)

2014年5月3日土曜日

Macのrubyバージョンをrbenvであげる

Macには初めからrubyがインストールされていますが、最新のバージョンを入れたいのと、
複数のバージョンを入れたいのでrbenvを入れたいと思います。

rbenbはhomebrewで入れられます。
$ brew install rbenv
==> 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 3 seconds

以下のコマンドを実行する。
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile

次にruby-buildを入れます。これもhomebrewで入ります。
$ brew install ruby-build
==> Installing dependencies for ruby-build: autoconf, pkg-config, openssl
==> Installing ruby-build dependency: autoconf
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/autoconf-2.69.mavericks.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring autoconf-2.69.mavericks.bottle.1.tar.gz
🍺  /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M
==> Installing ruby-build dependency: pkg-config
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-0.28.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.28.mavericks.bottle.2.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.28: 10 files, 604K
==> Installing ruby-build dependency: openssl
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.1g.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.1g.mavericks.bottle.tar.gz
==> 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.1g: 429 files, 15M
==> Installing ruby-build
==> Downloading https://github.com/sstephenson/ruby-build/archive/v20140408.tar.gz
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/20140408: 114 files, 488K, built in 2 seconds

次に関連するrbenv-gemset、rbenv-gem-rehash、readline、apple-gcc42をhomebrewで入れます。
$ brew install rbenv-gemset
==> Downloading https://github.com/jf/rbenv-gemset/archive/v0.5.6.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/rbenv-gemset/0.5.6: 12 files, 52K, built in 3 seconds

$ brew install rbenv-gem-rehash
==> Downloading https://github.com/sstephenson/rbenv-gem-rehash/archive/v1.0.0.tar.gz
######################################################################## 100.0%
==> Downloading https://github.com/sstephenson/rbenv-gem-rehash/commit/0756890cfd9c7bbbdde38560fe81626a0c5769bd.patch
######################################################################## 100.0%
==> Patching
patching file README.md
Hunk #1 succeeded at 23 (offset -2 lines).
patching file etc/rbenv.d/exec/~gem-rehash.bash
patching file gems/rbenv-gem-rehash-1.0.0/lib/rubygems_plugin.rb
patching file rubygems_plugin.rb
patching file specifications/rbenv-gem-rehash-1.0.0.gemspec
==> Caveats
If the GEM_PATH environment variable is undefined, rbenv-gem-rehash must
first execute the gem env gempath command to retrieve RubyGems' default path
so that it can can append to the path rather than override it. This can take
a while--from a few hundred milliseconds on MRI to several seconds on
JRuby--so the default path for the current Ruby version is cached to the
filesystem the first time it is retrieved.
==> Summary
🍺  /usr/local/Cellar/rbenv-gem-rehash/1.0.0: 7 files, 24K, built in 3 seconds

$ brew install readline
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.2.4.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring readline-6.2.4.mavericks.bottle.2.tar.gz
==> 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.6M

$ brew install apple-gcc42
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/apple-gcc42-4.2.1-5666.3.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring apple-gcc42-4.2.1-5666.3.mavericks.bottle.2.tar.gz
==> Caveats
NOTE:
This formula provides components that were removed from XCode in the 4.2
release. There is no reason to install this formula if you are using a
version of XCode prior to 4.2.
 
This formula contains compilers built from Apple's GCC sources, build
5666.3, available from:
 
  http://opensource.apple.com/tarballs/gcc
 
All compilers have a `-4.2` suffix. A GFortran compiler is also included.
==> Summary
🍺  /usr/local/Cellar/apple-gcc42/4.2.1-5666.3: 104 files, 75M

homebrewのインストールが終わった状態はこんな感じです。
$ brew list
apple-gcc42  mysql   pcre   rbenv-gem-rehash ruby-build
autoconf  nginx   pkg-config  rbenv-gemset  tomcat
brew-cask  openssl   rbenv   readline

ではrubyのバージョンをあげたいと思います。
まずは今のバージョンがこちら。
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

rbenbで入れられるバージョンが以下のものです。
$ 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.8.7-p371
  1.8.7-p374
  1.8.7-p375
  1.9.1-p378
  1.9.1-p430
  1.9.2-p0
  1.9.2-p180
  1.9.2-p290
  1.9.2-p318
  1.9.2-p320
  1.9.2-p326
  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-p362
  1.9.3-p374
  1.9.3-p385
  1.9.3-p392
  1.9.3-p429
  1.9.3-p448
  1.9.3-p484
  1.9.3-p545
  1.9.3-preview1
  1.9.3-rc1
  2.0.0-dev
  2.0.0-p0
  2.0.0-p195
  2.0.0-p247
  2.0.0-p353
  2.0.0-p451
  2.0.0-preview1
  2.0.0-preview2
  2.0.0-rc1
  2.0.0-rc2
  2.1.0
  2.1.0-dev
  2.1.0-preview1
  2.1.0-preview2
  2.1.0-rc1
  2.1.1
  2.2.0-dev
  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
  jruby-1.7.1
  jruby-1.7.10
  jruby-1.7.11
  jruby-1.7.2
  jruby-1.7.3
  jruby-1.7.4
  jruby-1.7.5
  jruby-1.7.6
  jruby-1.7.7
  jruby-1.7.8
  jruby-1.7.9
  jruby-9000+graal-dev
  jruby-9000-dev
  maglev-1.0.0
  maglev-1.1.0-dev
  maglev-2.0.0-dev
  mruby-1.0.0
  mruby-dev
  rbx-1.2.4
  rbx-2.0.0
  rbx-2.0.0-dev
  rbx-2.0.0-rc1
  rbx-2.1.0
  rbx-2.1.1
  rbx-2.2.0
  rbx-2.2.1
  rbx-2.2.2
  rbx-2.2.3
  rbx-2.2.4
  rbx-2.2.5
  rbx-2.2.6
  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
  topaz-dev

バージョン2.1.1を入れてみます。
$ rbenv install 2.1.1
Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
Installing yaml-0.1.6...
Installed yaml-0.1.6 to /Users/xxxx/.rbenv/versions/2.1.1
 
Downloading ruby-2.1.1.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/e57fdbb8ed56e70c43f39c79da1654b2
Installing ruby-2.1.1...
Installed ruby-2.1.1 to /Users/xxxx/.rbenv/versions/2.1.1

まだこの段階ではバージョンは変わっていません。
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

選べるrubyのバージョンを確認すると、まだ初期から入っているrubyが使われています。
$ rbenv versions
* system (set by /Users/xxxx/.rbenv/version)
  2.1.1

デフォルトで使うバージョンを変更します。
$ rbenv global 2.1.1

$ rbenv versions
  system
* 2.1.1 (set by /Users/xxxx/.rbenv/version)

あれ、変わりません。。。
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

ログアウトしてコンソール立ち上げ直して再度やったらバージョン変わりました。
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]


参考URL
http://qiita.com/skinoshita/items/2cf0c27a6ff4f0602568
https://gist.github.com/mochiz/4736183
http://www.d-wood.com/blog/2014/03/20_5847.html