やりたいこと
・混在しているrails環境の一斉清掃。
・各バージョンのパッケージ管理をrvmからrbenvへ移行。
・Rails 3.2.13 + Ruby 1.9.3 と Rails 4.0.0 + Ruby 2.0.0 の環境を用意する。
RVM環境を切腹w
$ rvm seppuku
さすが切腹。サクッと消えました。
OSをインストールしたばかりの場合|必要なパッケージをインストール
# apt-get install build-essential bison libreadline6-dev curl git-core zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev autoconf libncurses5-dev
rbenvのインストール
※aptで入れようとするとlibreadline5 libruby1.8 libruby1.9.1 ruby ruby1.8 ruby1.9.1のパッケージまで入ってしまうw ここはgitで。
本家様:https://github.com/sstephenson/rbenv
$ git clone git://github.com/sstephenson/rbenv.git .rbenv Cloning into '.rbenv'... remote: Counting objects: 1651, done. remote: Compressing objects: 100% (679/679), done. remote: Total 1651 (delta 1060), reused 1467 (delta 940) Receiving objects: 100% (1651/1651), 240.31 KiB | 55 KiB/s, done. Resolving deltas: 100% (1060/1060), done.
パスを通す
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc $ echo 'eval "$(rbenv init -)"' >> ~/.bashrc $ source ~/.bashrc
ruby-buildのインストール
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build Cloning into '/home/username/.rbenv/plugins/ruby-build'... remote: Counting objects: 2157, done. remote: Compressing objects: 100% (1258/1258), done. remote: Total 2157 (delta 957), reused 1883 (delta 712) Receiving objects: 100% (2157/2157), 288.09 KiB | 48 KiB/s, done. Resolving deltas: 100% (957/957), done. $ cd ~/.rbenv/plugins/ruby-build $ sudo ./install.sh Installed ruby-build at /usr/local
インストールできるパッケージの確認
$ rbenv install --list 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.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.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-preview1 1.9.3-rc1 2.0.0-dev 2.0.0-p0 2.0.0-p195 2.0.0-p247 2.0.0-preview1 2.0.0-preview2 2.0.0-rc1 2.0.0-rc2 2.1.0-dev 〜 以下省略 〜
Rubyバージョン1.9.3-p448をインストール
$ rbenv install 1.9.3-p448
Rubyバージョン2.0.0-p247をインストール
$ rbenv install 2.0.0-p247
rbenvの更新
$ rbenv rehash
1.9.3-p448をデフォルトに指定
$ rbenv global 1.9.3-p448
インストールしたRubyバージョンの確認
デフォルトに指定したバージョンを表示
$ ruby --version ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]
すべてのバージョンを表示
$ rbenv versions * 1.9.3-p448 (set by /home/username/.rbenv/version) 2.0.0-p247
bundlerをインストール
$ gem i bundler Fetching: bundler-1.3.5.gem (100%) Successfully installed bundler-1.3.5 1 gem installed Installing ri documentation for bundler-1.3.5... Installing RDoc documentation for bundler-1.3.5...
Rails v3.2.13をインストール
$ gem i rails -v 3.2.13 〜 以下省略 〜
Rails v4.0.0をインストール
gem i rails -v 4.0.0 〜 以下省略 〜
RailsProject毎のRubyバージョン管理
Rails v3.2.13 と v4.0.0のプロジェクトをそれぞれ作成。
後にGemパッケージをプロジェクト単位で管理するのでbundle installはスキップ指定。
$ rails _3.2.13_ new sample_project3213 --skip-bundle 〜 以下省略 〜 $ rails _4.0.0_ new sample_project400 --skip-bundle 〜 以下省略 〜
適用するRubyバージョンをローカル指定
sample_project3213
Rubyバージョン1.9.3-p448を適用。
$ cd sample_project3213 $ rbenv local 1.9.3-p448
sample_project3213内でRubyのバージョンを確認してみる。
$ ruby -v ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]
sample_project400
Rubyバージョン2.0.0-p247を適用。
$ cd sample_project400 $ rbenv local 2.0.0-p247
sample_project400内でRubyのバージョンを確認してみる。
$ ruby -v ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
bundle installにpathオプションを指定してプロジェクト毎にGemパッケージを管理する。
sample_project3213
$ cd sample_project3213 $ bundle install --path vendor/bundle 〜 以下省略 〜 Your bundle is complete! It was installed into ./vendor/bundle
プロジェクト内にbundle installされたGemパッケージ一覧を表示。
$ bundle list Gems included by the bundle: * actionmailer (3.2.13) * actionpack (3.2.13) * activemodel (3.2.13) * activerecord (3.2.13) * activeresource (3.2.13) * activesupport (3.2.13) * arel (3.0.2) * builder (3.0.4) * bundler (1.3.5) * coffee-rails (3.2.2) * coffee-script (2.2.0) * coffee-script-source (1.6.3) * erubis (2.7.0) * execjs (2.0.1) * hike (1.2.3) * i18n (0.6.1) * journey (1.0.4) * jquery-rails (3.0.4) * json (1.8.0) * mail (2.5.4) * mime-types (1.25) * multi_json (1.8.0) * polyglot (0.3.3) * rack (1.4.5) * rack-cache (1.2) * rack-ssl (1.3.3) * rack-test (0.6.2) * rails (3.2.13) * railties (3.2.13) * rake (10.1.0) * rdoc (3.12.2) * sass (3.2.10) * sass-rails (3.2.6) * sprockets (2.2.2) * sqlite3 (1.3.8) * thor (0.18.1) * tilt (1.4.1) * treetop (1.4.15) * tzinfo (0.3.37) * uglifier (2.2.1)
Railsバージョンを確認
$ rails -v Rails 3.2.13
sample_project400
$ cd sample_project400 $ bundle install --path vendor/bundle 〜 以下省略 〜 Your bundle is complete! It was installed into ./vendor/bundle
プロジェクト内にbundle installされたGemパッケージ一覧を表示。
$ bundle list Gems included by the bundle: Gems included by the bundle: * actionmailer (4.0.0) * actionpack (4.0.0) * activemodel (4.0.0) * activerecord (4.0.0) * activerecord-deprecated_finders (1.0.3) * activesupport (4.0.0) * arel (4.0.0) * atomic (1.1.14) * builder (3.1.4) * bundler (1.3.5) * coffee-rails (4.0.0) * coffee-script (2.2.0) * coffee-script-source (1.6.3) * erubis (2.7.0) * execjs (2.0.1) * hike (1.2.3) * i18n (0.6.5) * jbuilder (1.5.1) * jquery-rails (3.0.4) * json (1.8.0) * mail (2.5.4) * mime-types (1.25) * minitest (4.7.5) * multi_json (1.8.0) * polyglot (0.3.3) * rack (1.5.2) * rack-test (0.6.2) * rails (4.0.0) * railties (4.0.0) * rake (10.1.0) * rdoc (3.12.2) * sass (3.2.10) * sass-rails (4.0.0) * sdoc (0.3.20) * sprockets (2.10.0) * sprockets-rails (2.0.0) * sqlite3 (1.3.8) * thor (0.18.1) * thread_safe (0.1.3) * tilt (1.4.1) * treetop (1.4.15) * turbolinks (1.3.0) * tzinfo (0.3.37) * uglifier (2.2.1)
Railsバージョンを確認
$ rails -v Rails 4.0.0
Fantastic!!!
閉店ガラガラ