Install and use bundler in Ruby to manage multiple versions of gem and rubybundler
With rbenv to manage a multi-version ruby environment, we also need a tool that can manage multiple versions of gem (such as rails), that is, bundler. The project background is not detailed, for more information, visit http://bundler.io/on the official website.
Install
gem install bundler
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 rails 4.1.0 under app1, use bundle exec rails -v to view the version of rails used in the current directory, the display content should be Rails 4.1.0, also at this time through bundle exec rails new. Gemfile, the rails version 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 above code creates a second app2 folder and installs rails 3.2.13 through bundler. Also through bundle exec rails new. --Force can generate applications based on rails 3.2.13
After installing the above two versions, you can see through the gem list --local that there are two versions of rails, which are displayed as rails (4.1.0, 3.2.13). The application runs correctly, but only if the original command is executed by using the bundle exec command, for example:
bundle exec rails s
bundle exec rake db: create
...