Skip to content

Instantly share code, notes, and snippets.

@chrismo
Last active October 19, 2016 20:32
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrismo/5043420 to your computer and use it in GitHub Desktop.
Save chrismo/5043420 to your computer and use it in GitHub Desktop.
Bundler 1.3 --binstubs vs. Rails 4

On a clean Rails 4 install with Bundler 1.3.0, using --binstubs causes competition between Rails and Bundler for the contents of bin/rails (and bin/rake).

Just running bundle will rewrite the Rails version of bin/rails to a version that doesn't work.

The fix is to use the new bundle binstubs <gemname> command.

(see rails/rails#8974)

$ cat Gemfile
source 'https://rubygems.org'
ruby "2.0.0"
gem 'rails', github: 'rails/rails'
$ bundle install --path zz --binstubs
Fetching git://github.com/rails/rails.git
...
[snip]
...
$ cat .bundle/config
---
BUNDLE_PATH: zz
BUNDLE_BIN: bin
BUNDLE_DISABLE_SHARED_GEMS: '1'
$ bundler -v
-bash: bundler: command not found
$ bundle -v
Bundler version 1.3.0
$ cat bin/rails
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
$ bundle
Using rake (10.0.3)
...
[snip]
...
Your bundle is complete! It was installed into ./zz
$ cat bin/rails
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rails' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('railties', 'rails')
$ bin/rake rails:update:bin
exist bin
identical bin/bundle
conflict bin/rails
Overwrite /Volumes/modev/bundler-rails/bin/rails? (enter "h" for help) [Ynaqdh] n
skip bin/rails
conflict bin/rake
Overwrite /Volumes/modev/bundler-rails/bin/rake? (enter "h" for help) [Ynaqdh] n
skip bin/rake
$ bin/rails s
Usage:
rails new APP_PATH [options]
...
#### FIX ####
$ rm -rf .bundle/
$ rm -rf zz
$ rm -rf bin
$ bundle install --path zz
Fetching gem metadata from https://rubygems.org/.........
...
[snip]
...
$ ls bin
ls: bin: No such file or directory
$ bundle exec rake rails:update:bin
create bin
create bin/bundle
create bin/rails
create bin/rake
$ bin/rails s
=> Booting WEBrick
...
[snip]
...
$ bundle binstubs rdoc
$ ls bin
bundle rails rake rdoc ri
$ bin/rdoc
Parsing sources...
^C3% [115/3555] ...04/actionpack/lib/action_controller/metal/instrumentation.rb
Interrupted
$ bundle
Using rake (10.0.3)
...
[snip]
...
$ bin/rails s
=> Booting WEBrick
...
@chrismo
Copy link
Author

chrismo commented Feb 27, 2013

I shouldn't have included the --path stuff, it's irrelevant to all this, but 'tis my practice to use.

@steveklabnik
Copy link

Don't do --binstubs, use bundle binstubs <gem> for the ones you want. After you generate a project, you'll have three things there:

$ ls bin
bundle rails  rake

bin/rails s should work right away.

If you add a gem that you want an executable for....

$ tail Gemfile

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano', group: :development

# To use debugger
# gem 'debugger'
gem 'rspec-rails'

and you bundle, it's the same:

$ bundle
<snip>
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

steve at thoth in ~/tmp/beta_one on master!
$ ls bin
bundle rails  rake

So you use binstubs:

$ bundle binstubs rspec-rails                                                                                                       ✘
rspec-rails has no executables, but you may want one from a gem it depends on.
  railties has: rails
  rspec-core has: autospec, rspec

steve at thoth in ~/tmp/beta_one on master!
$ bundle binstubs rspec-core

steve at thoth in ~/tmp/beta_one on master!
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   Gemfile
#   modified:   Gemfile.lock
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   bin/autospec
#   bin/rspec
no changes added to commit (use "git add" and/or "git commit -a")

steve at thoth in ~/tmp/beta_one on master!
$ bin/rspec
/Users/steve/.gem/ruby/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in `load': cannot load such file -- /Users/steve/tmp/beta_one/spec (LoadError)
    from /Users/steve/.gem/ruby/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from /Users/steve/.gem/ruby/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in `each'
    from /Users/steve/.gem/ruby/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from /Users/steve/.gem/ruby/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/steve/.gem/ruby/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:80:in `run'
    from /Users/steve/.gem/ruby/2.0.0/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:17:in `block in autorun'
steve at thoth in ~/tmp/beta_one on master!
[1] $ mkdir spec                                                                                                                        ✘

steve at thoth in ~/tmp/beta_one on master!
$ bin/rspec 
No examples found.


Finished in 0.00008 seconds
0 examples, 0 failures

Now you commit the Gemfile and your bin/ directory.

@wuputah
Copy link

wuputah commented Mar 2, 2013

Alternatively:

bundle install --path .bundle --binstubs .bundle/bin
export PATH="bin:.bundle/bin:$PATH"

(I'm not sure how I feel about the $PATH modifications, though.)

@elskwid
Copy link

elskwid commented Jun 5, 2013

@wuputah, I do the same thing and put the binstubs under .bundle/bin. I don't modify the path though, too risky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment