8

Homebrew's Ruby 1.9 ships with rubygems. Doing gem install ... installs files and binaries into some long-winded path. For example, bundler is installed at:

/usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/bin/bundle

I'd like to have gem automatically symlink these binaries into a common location such as /usr/local/bin so that I don't have to manually link each of these binaries. Is this possible?

slhck
  • 223,558
  • 70
  • 607
  • 592
Sridhar Ratnakumar
  • 4,759
  • 10
  • 43
  • 56

5 Answers5

6

Related question on StackOverflow: Installing Ruby gems not working with Home Brew

This little one-liner works perfect and is faster than querying brew-info:

export PATH=$(brew --prefix ruby)/bin:$PATH

More info in my answer there.

Timo Tijhof
  • 169
  • 1
  • 5
5
# Install 1 or more gems
gem install rails
gem install aws-sdk
# Then run these 2 commands to create bin links
brew unlink ruby
brew link ruby
# Finally open a new terminal session (no idea why but it worked for me)
Jim Cleveland
  • 51
  • 1
  • 1
  • Actually even if the gem bin doesn't autocomplete, you can type it, it's in the path. You don't have to restart a terminal session. – bric3 Sep 07 '12 at 09:03
  • Homebrew no longer links ruby, as it refuses to shadow binaries provided by OS X. You can put the ruby binary in your path, but it doesn't add binaries provided by gems. – GDorn May 27 '19 at 14:29
4

I ended up adding the following lines to .bashrc

RUBY_BINDIR=`brew info ruby|grep /bin|tr -d ' '`
export PATH=$RUBY_BINDIR:$PATH

The afore-mentioned brewbygems is not what you want, it's meant for the osx-builtin ruby and homebrew to play nice together, not if you installed ruby itself via homebrew.

Fabian Zeindl
  • 308
  • 1
  • 10
  • This solved my problem of getting import failures for compass plugins during compiling a compass project, because it internally used macs builtin version of ruby. – jfd Aug 09 '12 at 08:32
1

This worked for me: brewbygems

I followed the instructions on that site, and installed the 'brewbygems' gem before (re)installing my ruby gems. As far as I can tell, brewbygems extends the gem system to make it aware of Homebrew. It then takes care of symlinking in the binaries when gems are installed.

Andy Jackson
  • 111
  • 3
0

If you don’t want to touch your dot file, You can try:

brew unlink ruby && brew link ruby

New gems binaries symlinks will be created:

Unlinking /usr/local/Cellar/ruby/2.0.0-p0... 20 links removed
Linking /usr/local/Cellar/ruby/2.0.0-p0... 25 symlinks created
sparanoid
  • 151
  • 1
  • 5