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
...
@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