48

I've just made the switch from rvm to rbenv and I'm trying to use bundler for gem management. After running bundle install and trying to run a simple sinatra app (ruby app.rb), I get this:

Could not find haml-3.1.4 in any of the sources
Run `bundle install` to install missing gems.

Running bundle install again had no effect. Also tried bundle update as suggested by another question response.

This is my Gemfile:

source "http://rubygems.org"

gem "sinatra"
gem "haml"

This is what bundle show produces

* bundler (1.0.22)
* haml (3.1.4)
* rack (1.4.1)
* rack-protection (1.2.0)
* sinatra (1.3.2)
* tilt (1.3.3)

This is what my app requires:

require "rubygems"
require "bundler/setup"
require 'sinatra'

I'm convince that this is some kind of path issue where bundler and rbenv aren't playing along. I've tried looking through rbenv's documentation but was not able to find to anything.

Note: In a different sinatra app I get the following when trying to run it:

Could not find addressable-2.2.7 in any of the sources
Run `bundle install` to install missing gems.

Supplemental info

echo $PATH
/Users/uri/.rbenv/shims:/Users/uri/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

which bundle
/Users/uri/.rbenv/shims/bundle

Update

If I do bundle install --system it works. Although I can't see this as being a viable solution.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
Uri
  • 2,306
  • 2
  • 24
  • 25

10 Answers10

106

I was having the same issue. One hint was that rbenv exec bundle exec command worked and that rbenv exec bundle install --path vendor/bundle worked, but their prefixed equivalents failed.

I wiped my ~/.rbenv, ~/.gem Gemfile.lock and vendor/bundle a few times trying to start fresh. Once these were cleaned away I tried the following:

rbenv install 1.9.3-p194
rbenv rehash # for paranoia's sake
rbenv global 1.9.3-p194
gem env # to check that everything was pointing at 1.9 and not the system
gem install --no-ri --no-rdoc bundler
rbenv rehash # necessary to load up the bundle executable
bundle --path=vendor/bundle

and it worked!

I think the important thing, since I tried this a few times, is to remove the .gem file from your home directory. It seems to get in the way.

kweerious
  • 1,356
  • 1
  • 11
  • 16
  • You are my hero :) I think everything went haywire when I installed bundler before using rbenv to change to 1.9.3 – Jason Jul 30 '12 at 19:32
  • 2
    You saved me mentioning ~/.gem, now bundle-install works well! – sinm Sep 04 '12 at 05:55
  • 4
    Thanks a lot! I'm pretty sure my problem was that I didn't run `rbenv rehash` after I installed Bundler again. After `gem install bundler && rbenv rehash && bundle install` while using an rbenv Ruby the error was gone! – rkallensee Oct 01 '13 at 14:09
  • 4
    I logged in to upvote you. This problem was beginning to drive me crazy. The command that seemed to do it was `gem install --no-ri --no-rdoc bundler` and `rbenv rehash` – Nick Evans Dec 07 '13 at 00:54
  • 1
    It's a contradiction with the gem path. I just had the same problem...my bundle install ran but a subsequent gem list didn't show them. I renamed my ~/.gem in .gem_old and now the second position in my apps gem_path is being used...and this one actually contains the necessary gems. I still don't quite understand the gem path thing... – Ekkstein Jan 29 '14 at 18:13
  • 1
    `gem install --no-ri --no-rdoc bundler` was the missing trick for me. Thanks! – Adam Kalnas Mar 14 '14 at 19:56
  • `bundle --path=vendor/bundle` was all the magic I needed to get rake to work, apparently! Thanks :) – Wes Johnson Jan 12 '15 at 21:21
23

Have you run

rbenv rehash

This will provide shims for all ruby binaries, including ones installed by gems.

Ben Woodall
  • 1,264
  • 9
  • 7
20

Adding this

set :default_environment, {
  'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}

to deploy.rb worked for me.

http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/

thdr
  • 386
  • 3
  • 6
6

I suggest you use the gem 'capistrano-rbenv' (https://github.com/yyuu/capistrano-rbenv )

  1. make sure you have "rbenv" and a ruby version (e.g. 1.9.3) installed in remote server

  2. in your config/deploy.rb (capistrano file)

    require 'capistrano-rbenv'
    
  3. in your Gemfile:

    gem 'capistrano-rbenv', '1.0.1'
    
  4. that's it. to debug if it works, just run:

    $ cap shell
    cap> which ruby
     ** [out :: 10.103.13.74] /root/.rbenv/shims/ruby
    cap> ruby -v
     ** [out :: 10.103.13.74] ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
    
Siwei
  • 19,858
  • 7
  • 75
  • 95
  • This resolved my bundle not found issue when deploying, although it was available while logged in directly to the box. – Nath Apr 10 '13 at 20:08
2

You should try using chruby. chruby is an ultra-minimal (~80 lines) alternative to RVM / rbenv. Unlike rbenv, chruby does not rely on shims and simply modifies PATH, GEM_HOME and GEM_PATH.

postmodern
  • 454
  • 3
  • 3
2

I had a similar problem when I switched from using rvm to rbenv. I found my bundler was showing a different list of gems than my gem list command. First check to see which paths your bundler and gem are using. For bundler use the show command and select any gem.

$ bundle show ffi
/my/project/path/vendor/ruby/1.9.1/gems/ffi-1.1.5

and my gem environment command (in part)

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin10.8.0]
  - INSTALLATION DIRECTORY: /Users/rolf/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1

Here I could see my gem is pointing to the correct rbenv path but my bundler is pointing to my project's vendor path.

Running the following command should fix the bundler path problem:

$ bundle install --system

Bundler path should now be pointing to the rbenv path.

$ bundle show ffi
/Users/rolf/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/ffi-1.1.5

Also I found when I run the rvm implode command to uninstall rvm, there were still the following files which I needed to change to remove rvm paths:

~/.profile
~/.bashrc
~/.zshrc

If the ~/.rvm path still exists, you will need to remove this.

You will need to open a new terminal session after changing these files. Finally after all that I finally got my bundler and gem in sync.

rlawrenz
  • 146
  • 3
1

Just a reminder too that rbenv is not compatible with rvm they do not play nicely. For your sanity, uninstall rvm if you want to use rbenv. From the rbenv README:

Compatibility note: rbenv is incompatible with rvm. Things will appear to work until you try to install a gem. The problem is that rvm actually overrides the gem command with a shell function! Please remove any references to rvm before using rbenv.

Luckily, Wayne (rvm creator) provides a remove rvm easily using:

rvm implode

As a regular use or:

rvmsudo rvm implode

To clean rvm system wide.

ajhit406
  • 1,405
  • 1
  • 14
  • 17
1

I tried all the stuff here, but what did it for me was discovering that I had a .bundler in my user home directory for some reason. This was causing the weird problem above where the 'which' command correctly listed bundle in the shims path, but checking bundle -v showed the old system version, while /Users/jerimiah/.rbenv/shims/bundle showed the latest versions. I deleted .bundler in my home directory, rehashed, restarted my terminal, and everything started working.

jerimiah797
  • 4,525
  • 1
  • 14
  • 13
0

Give this rbenv plugin a try, it will make shims aware of the bundler paths

https://github.com/carsomyr/rbenv-bundler

CodedReality
  • 76
  • 1
  • 3
0

For anyone coming across this issue. This is the easiest solution to the "Can't find gem bundle situation (>= 0.a)

Command:

gem update --system 

Then update bundler command:

bundle update --bundler
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Bradley
  • 922
  • 2
  • 8
  • 24