How I Use Bundler

Posted by Christopher Rigor on February 11, 2010 
Filed Under Ruby on Rails

You probably heard that rails 3 beta is out and you want to try it. The instructions tell you to install the gems

gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
gem install rails --pre

Here, I’ll give you an alternative to installing rails 3 beta using bundler 0.9.3. This is for those who don’t want to mix the rails 3 gems with their system gems, or who don’t want to use rubygems. Well you still need rubygems to install bundler.

gem install bundler

After that, we create a gemfile on a directory that I’ll name ‘envs’.

$ mkdir envs
$ cd envs
$ vi Gemfile
source "http://gemcutter.org"
gem "rails", "3.0.0.beta"
$ bundle install r3b
Resolving dependencies
Installing abstract (1.0.0) from rubygems repository at http://gemcutter.org
Installing actionmailer (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing actionpack (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activemodel (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activerecord (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activeresource (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing activesupport (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing arel (0.2.1) from rubygems repository at http://gemcutter.org
Installing builder (2.1.2) from rubygems repository at http://gemcutter.org
Installing bundler (0.9.3) from rubygems repository at http://gemcutter.org
Installing erubis (2.6.5) from rubygems repository at http://gemcutter.org
Installing i18n (0.3.3) from rubygems repository at http://gemcutter.org
Installing mail (2.1.2) from rubygems repository at http://gemcutter.org
Installing memcache-client (1.7.8) from rubygems repository at http://gemcutter.org
Installing mime-types (1.16) from rubygems repository at http://gemcutter.org
Installing rack (1.1.0) from rubygems repository at http://gemcutter.org
Installing rack-mount (0.4.7) from rubygems repository at http://gemcutter.org
Installing rack-test (0.5.3) from rubygems repository at http://gemcutter.org
Installing rails (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing railties (3.0.0.beta) from rubygems repository at http://gemcutter.org
Installing rake (0.8.7) from rubygems repository at http://gemcutter.org
Installing text-format (1.0.0) from rubygems repository at http://gemcutter.org
Installing text-hyphen (1.0.0) from rubygems repository at http://gemcutter.org
Installing thor (0.13.0) from rubygems repository at http://gemcutter.org
Installing tzinfo (0.3.16) from rubygems repository at http://gemcutter.org
Your bundle is complete!
$ bundle show
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.0.beta)
* actionpack (3.0.0.beta)
* activemodel (3.0.0.beta)
* activerecord (3.0.0.beta)
* activeresource (3.0.0.beta)
* activesupport (3.0.0.beta)
* arel (0.2.1)
* builder (2.1.2)
* bundler (0.9.3)
* erubis (2.6.5)
* i18n (0.3.3)
* mail (2.1.2)
* memcache-client (1.7.8)
* mime-types (1.16)
* rack (1.1.0)
* rack-mount (0.4.7)
* rack-test (0.5.3)
* rails (3.0.0.beta)
* railties (3.0.0.beta)
* rake (0.8.7)
* text-format (1.0.0)
* text-hyphen (1.0.0)
* thor (0.13.0)
* tzinfo (0.3.16)

I like to create my rails apps on a separate directory outside of envs. We need to specify the location of the Gemfile.

$ cd ..
$ bundle show
The default Gemfile was not found

We need to specify the location of the Gemfile.

$ export BUNDLE_GEMFILE="/Users/crigor/admoolabs/envs/Gemfile"
$ bundle show
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.0.beta)
* actionpack (3.0.0.beta)
...

You can now run the rails command using bundle exec.

$ rails -v
Rails 2.3.4
$ bundle exec rails -v
Rails 3.0.0.beta

Let’s create the rails app named labsapp.

$ bundle exec rails labsapp
      create
      create  README
      create  .gitignore
      create  Rakefile
      create  config.ru
      create  Gemfile
      create  app
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/models
      create  app/views/layouts
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/cookie_verification_secret.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/session_store.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  log
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/application.js
      create  public/javascripts/controls.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/effects.js
      create  public/javascripts/prototype.js
      create  public/javascripts/rails.js
      create  script
      create  script/rails
      create  test
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/unit
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep

Let’s run the console.

$ cd labsapp
$ ./script/rails c
Loading development environment (Rails 3.0.0.beta)
irb(main):001:0> Rails.version
=> "3.0.0.beta"
irb(main):002:0> Rack.version
=> "1.1"

You now have the rails 3 gems separate from rails 2.x gems. Only the rails 2.x gems are installed on the system.

$ gem list rails
rails (2.3.4, 2.3.2, 2.2.2, 2.1.1, 2.1.0)

Comments

blog comments powered by Disqus