rvm による ruby 環境の自動切り替え の変更点
更新- 追加された行はこの色です。
- 削除された行はこの色です。
- ソフトウェア/rails/rvm による ruby 環境の自動切り替え へ行く。
- ソフトウェア/rails/rvm による ruby 環境の自動切り替え の差分を削除
[[公開メモ]]
* rvmのgemsetを使ってbundlerと賢く付き合う方法 [#ffb343ea]
- http://blog.s21g.com/articles/1930
- http://qiita.com/prinum/items/ac9feadbbe497649ab3f
これらを読むと、bundle exec が必要なくなるようなことが書いてある!
* やってみる [#ee3354dd]
LANG:console
$ rvm use 1.9 # ruby 1.9 を使う
Using /home/osamu/.rvm/gems/ruby-1.9.3-p551
$ gem list | head # たくさんインストールされている
actionmailer (4.0.8)
actionpack (4.0.8)
activemodel (4.0.8)
activerecord (4.0.8)
activerecord-deprecated_finders (1.0.4)
activesupport (4.0.8)
ansi (1.5.0)
arel (6.0.3, 4.0.2)
better_errors (1.1.0)
bigdecimal (1.1.0)
$ rvm gemset create ICSPM24 # 適当な名前で空の gemset を作成
ruby-1.9.3-p551 - #gemset created /home/osamu/.rvm/gems/ruby-1.9.3-p551@ICSPM24
ruby-1.9.3-p551 - #generating ICSPM24 wrappers........
$ rvm gemset use ICSPM24 # それを使う
Using ruby-1.9.3-p551 with gemset ICSPM24
$ gem list # 自分でインストールしたものが消えた
*** LOCAL GEMS ***
bigdecimal (1.1.0)
bundler (1.7.6)
bundler-unload (1.0.2)
executable-hooks (1.3.2)
gem-wrappers (1.2.7)
io-console (0.3)
json (1.5.5)
minitest (2.5.1)
rake (0.9.2.2)
rdoc (3.9.5)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
$ which bundle # 正しいバージョンが使われることを確認
/home/osamu/.rvm/gems/ruby-1.9.3-p551@ICSPM24/bin/bundle
$ bundle --version # 正しいバージョンが使われることを確認
Bundler version 1.7.6
$ bundle install --system # gem を導入する
Fetching source index from https://rubygems.org/
...
$ gem list | head # 結果を確認
actionmailer (4.0.8)
actionpack (4.0.8)
activemodel (4.0.8)
activerecord (4.0.8)
activerecord-deprecated_finders (1.0.4)
activesupport (4.0.8)
ansi (1.5.0)
arel (4.0.2)
better_errors (1.1.0)
bigdecimal (1.1.0)
$ rvm gemset list # 現在の状況に合わせて
gemsets for ruby-1.9.3-p551 (found in /home/osamu/.rvm/gems/ruby-1.9.3-p551)
(default)
=> ICSPM24
global
$ # 設定ファイルを作成
$ rvm --create --ruby-version use ruby-1.9.3-p551@ICSPM24
Using /home/osamu/.rvm/gems/ruby-1.9.3-p551 with gemset ICSPM24
$ cat .ruby-version # 中身を確認
ruby-1.9.3-p551
$ cat .ruby-gemset # 中身を確認
ICSPM24
$ cd .. # このフォルダの外で
$ rvm use 2
Using /home/osamu/.rvm/gems/ruby-2.2.1
$ ruby --version # 違うバージョンの ruby と
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
$ gem list | head -4 # gemset を使っていても
actionmailer (4.2.6)
actionpack (4.2.6)
actionview (4.2.6)
active_scaffold (3.4.35)
$ cd ICSPM24 # 設定したフォルダに戻ると
$ ruby --version # 正しいバージョンが使われる
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
$ gem list | head -4 # gemset も
actionmailer (4.0.8)
actionpack (4.0.8)
activemodel (4.0.8)
activerecord (4.0.8)
これは便利だ。
* cgi などへの活用法 [#a3354327]
http://juzow.hatenablog.com/entry/20120307/1331126770
こんな風になるそうです。
LANG:ruby
#!/usr/local/rvm/rubies/ruby-1.9.3-p125/bin/ruby
$LOAD_PATH.unshift "/usr/local/rvm/gems/ruby-1.9.3-p125"
ENV['GEM_HOME'] = '/usr/local/rvm/gems/ruby-1.9.3-p125@name-of-gemset'
require 'rubygems'
print "Content-Type: text/html\n\n"
* passenger での利用方法 [#cce665a1]
/etc/apache2/site-enabled/*.conf にて、
/etc/apache2/site-enabled/*.conf にて、PassengerRuby に /(path to rvm/gems)/ruby-(version)@(gemset)/wrappers/ruby を与えれば良いそうです。
Alias /(project sub-url) /(project folder)
<Location /(project sub-url)>
PassengerRuby /usr/local/rvm/gems/ruby-1.9.3-p125@name-of-gemset/wrappers/ruby
PassengerAppRoot /(project folder)
</Location>
<Directory /(project folder)/public>
Allow from all
AllowOverride all
Options -MultiViews
</Directory>
* 質問・コメント [#yf83a892]
#article_kcaptcha
Counter: 4837 (from 2010/06/03),
today: 1,
yesterday: 1