Search code examples
rubybashmacosbundlerrbenv

Bundler with rbenv version pathfile issue


So I am using rbenv to set my ruby version (for the specific project I'm working on this is 2.1.1). The issue is that bundler is unable to detect this change. I even tried to set the version in my gemfile:

source "https://my-proxy-address"
ruby "2.1.1"
gem 'fileutils'
gem 'json'
gem 'chef-api'

However this then causes the exact error message as seen here at the end of the tutorial:

username@hostname:~/Desktop/working-bundler-env$ rbenv version
2.1.1 (set by /Users/username/.rbenv/version)
username@hostname:~/Desktop/working-bundler-env$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin15.0]
username@hostname:~/Desktop/working-bundler-env$ bundle install
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1

The tutorial has the solution to the issue (edit a pathfile), however they dont say what file to change. What file do I change?

$ rbenv
rbenv 1.0.0
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   install     Install a Ruby version using ruby-build
   uninstall   Uninstall a specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/rbenv/rbenv#readme

$ which bundle
/usr/local/bin/bundle

Solution

  • So I noticed that when I ran gem bundle install the version was 1.13.3. After running sudo find / -name bundle I found two file locations that included that version number.

    /Users/myusername/.gems/gems/bundler-1.13.3/exe/bundle
    /Users/myusername/.gems/gems/bundler-1.13.3/lib/bundler/man/bundle
    

    After attempting to run /Users/myusername/.gems/gems/bundler-1.13.3/exe/bundle install it works perfectly. So I just made an alias in my ~/.bash_profile that overwrote the incorrect bundle command.

    alias bundle=/Users/alexcohen/.gems/gems/bundler-1.13.3/exe/bundle
    

    The only side effect of this gem (for better or worse) is that it creates .bundle and path directories in the directory where I run bundle install where the gems are downloaded into.

    I still have to investigate why this is happening, but I think that the bundle command in my macs terminal was referencing some type of broken bundler gem or file somewhere in my system.