Search code examples
rubybundlerrbenv

How do I ensure ruby gems are installed in right place to be executed by bundler?


I seem to be constantly having problems with getting the gems in the right place (and not needing to use sudo when installing them.)

To address the sudo issue, I installed rbenv and then use that to install ruby 2.1.0 so that I had a separate one from Mac OSX system.

Then I installed bundler. But when I install gems from a Gemfile with bundler, I cannot find them.

Between all the steps I have taken, such as adding lines to my .bash_profile and so forth, I have the following, but really just want a clear, straightforward way to manage gems and their local execution:

gem env :

Edit: I removed everything and reset PATH -- still didn't fix anything, but you can see that gems are installed in one directory but when I call the executable, the command cannot be found:

 RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14
  - RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [universal.x86_64-darwin13]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-13
  - GEM PATHS:
     - /Library/Ruby/Gems/2.0.0
     - /Users/fongster/.gem/ruby/2.0.0
     - /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0

Here is what happens when I want to run, say shotgun:

bash-3.2$ shotgun /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:296:into_specs': Could not find 'shotgun' (>= 0) among 12 total gem(s) (Gem::LoadError)

Can someone point me to simple, straightforward directdions for ruby gem management on OSX so that:

  • I don't need to use sudo to install gems
  • I can use bundler to install from a Gemfile for a given project
  • Those gems and their executables (shotgun, restclient, sass) can just be executed
  • My local environment based on this set up 'just works' in heroku?
  • I don't need to type bundle exec when I need to do stuff

Also some clarity on whether I need to always go to a bash shell (currently, I have been using exec bash to get my shell working).

EDIT: Following the steps below and have this response upon bundle:

Errno::EEXIST: File exists @ dir_s_mkdir - /Users/fongster/.rbenv/shims/gem
An error occurred while installing backports (3.6.3), and Bundler cannot
continue.
Make sure that `gem install backports -v '3.6.3'` succeeds before bundling.

Solution

  • From a clean start

    You do not have to do anything apart from the plain steps stated on the Bundler home page:

    • Do NOT use sudo bundle ...
    • Do NOT change anything to your PATH
    • Do not touch any ~/.file

    • Copy require 'bundler/setup' at the top of your first application file

    • DO use bundle exec in front of all your Bundler-managed "binaries"

    Everything just works using the nice defaults for a developer workstation. When you want to go further like running multiples Rubies side by side or deploying to prod or are fed up with typing bundle exec (which you should alias to bex using alias bex='bundle exec') you can then Read The Full Manual, type bundle install --binstubs and install one of the Rubymongers (RBEnv, RVM).

    In your specific situation

    I would restart from scratch:

    • uninstall RBEnv (rm -rf ~/.rbenv and delete rbenv mentions in grep rbenv ~/.bashrc ~/.bash_profile ~/.zshrc /etc/profile /etc/profile.d/*)
    • uninstall Bundler