With RBENV to manage multiple versions of the Ruby environment, we also need a tool to manage multiple versions of gems (such as rails), which is bundler, the project background is not in detail, need to understand directly to the official website http://bundler.io/, There are only a few practical experiences to use here.
Installation
Use
mkdir App1; CD App1;
echo "Source ' https://ruby.taobao.org/'" > Gemfile
echo "Gem ' rails, ' 4.1.0 '" >> gemfile
Bundle Install
The above code installs the Rails 4.1.0 under App1, uses bundle EXEC rails-v to view the rails version that is used under the current directory, and the display content should be rails 4.1.0, also at this time through bundle exec rails new. --force overwrite the original gemfile, the version of the rails used by the app at this time is 4.1.0.
mkdir app2; CD app2;
echo "Source ' https://ruby.taobao.org/'" > Gemfile
echo "Gem ' rails, ' 3.2.13 '" >> gemfile
Bundle Install
The code above creates a second App2 folder and installs rails via bundler 3.2.13 also through bundle exec rails new. --force can generate applications based on the Rails 3.2.13 version.
With the above two versions installed, you can see from the Gem list--local that rails has two versions, shown as Rails (4.1.0, 3.2.13), and bundler intelligently judge the rails version of each project to ensure that the application runs correctly, But the premise is to execute the original command by using the bundle EXEC command, for example:
Bundle EXEC Rails s
bundle exec rake db:create
...