有了rbenv來管理多版本的ruby環(huán)境,我們還需要一個能管理多版本gem(比如rails)的工具,那就是bundler了,項(xiàng)目背景不細(xì)說了,需要了解的直接到官網(wǎng)http://bundler.io/,這里只講一些實(shí)際使用經(jīng)驗(yàn)。
安裝
gem install bundler
使用
mkdir app1; cd app1;echo "source 'https://ruby.taobao.org/'" > Gemfileecho "gem 'rails,'4.1.0'" >> Gemfilebundle install
上面代碼在app1下安裝了rails 4.1.0,使用bundle exec rails -v查看當(dāng)前目錄下使用的rails版本,顯示內(nèi)容應(yīng)該為Rails 4.1.0,同樣此時通過bundle exec rails new . --force覆蓋原來Gemfile,此時的app使用的rails版本為4.1.0。
mkdir app2; cd app2;echo "source 'https://ruby.taobao.org/'" > Gemfileecho "gem 'rails,'3.2.13'" >> Gemfilebundle install
上面代碼創(chuàng)建了第二個app2文件夾,并通過bundler安裝了rails 3.2.13 同樣通過bundle exec rails new . --force可以生成基于rails 3.2.13版本的應(yīng)用。
安裝了以上兩個版本后,通過gem list --local可以看到rails有兩個版本,顯示為rails (4.1.0, 3.2.13),bundler會智能的判斷每個項(xiàng)目的rails版本,以確保應(yīng)用的正確運(yùn)行,但前提是通過使用bundle exec命令來執(zhí)行原來得命令,例如:
bundle exec rails sbundle exec rake db:create...
新聞熱點(diǎn)
疑難解答
圖片精選