views:

1078

answers:

3

By default, when you sudo gem install thegemname it will install executables into /usr/bin/

Is there a way to change this? For example, to install them into /usr/local/rubygems/bin (or any other path)?

The path doesn't seem to be hard-coded into the gemspec file, so I don't see why this shouldn't be possible (although I have very little experience with Ruby/Gems)

+4  A: 

See http://www.rubygems.org/read/chapter/11 and specify a ~/.gemrc which defines a gemhome variable.

For example:

gemhome: /usr/local/rubygems

You can also place this file in /etc/gemrc

csl
Thanks! I hope you don't mind I updated your answer. I prodded around rubygems.rb - the bin dir is appended to gemhome, there doesn't seem any obvious way to override only this, but setting gemhome to /Library/Ruby/Gems/1.8/ (on OS X) gives a bin path of /Library/Ruby/Gems/1.8/bin which is perfect
dbr
Good update, thanks!
csl
Gah, not quite perfect. There is a default /usr/bin override for the Mac distribution..
dbr
+1  A: 

On OS X, the executable directory is overridden to /usr/bin in the file /Library/Ruby/Site/1.8/rubygems/defaults.rb

# The default directory for binaries
def self.default_bindir
  if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
    '/usr/bin'
  else # generic install
    ConfigMap[:bindir]
  end
end

As a hackish work around, I changed /usr/bin to my desired bin location, which works correctly. There doesn't seem to be any way to override bindir from the ~/.gemrc config?

dbr
This is really annoying. There is no way to change this because it depends on the global constant. And if you do change it everytime rubygems is updated you have to change it again. I'd like to shoot the guy responsible for this appalling decision.
Max Howell
Max Howell
Actually, we were wrong. You can change the bindir. I documented it here: http://wiki.github.com/mxcl/homebrew/cpan-ruby-gems-and-python-disttools
Max Howell
Updated wiki link that Max posted: http://wiki.github.com/mxcl/homebrew/gems-eggs-and-perl-modules
dbr
+1  A: 

I'm adding this as an answer so that it is obvious when I run into this problem again :)

First *, move all the bins in /var/lib/gems/1.8/bin/ to /usr/bin/.

Next, edit ~/.gemrc and add (or update) the following line:

gem: --bindir /usr/bin

This overrides gem so that it always uses /usr/bin/ as the bin dir.

No need to update the path (especially messy for multiple-user machines).

* If you don't do this, then uninstalling or updating a gem will not remove the binary from the original bin directory.

Updated: if you delete the old bin directory, make sure to remove it from the path.

BryanH
Yep, this seems to work perfectly (at least on Rubygem 1.3.6)
dbr