[ACCEPTED]-Can "gem install" be configured to install executables outside /usr/bin/ by default?-rubygems

Accepted answer
Score: 20

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

First, move all the bins in /var/lib/gems/1.8/bin/ to 8 /usr/bin/. If you don't do this, then uninstalling 7 or updating a gem will not remove the binary 6 from the original bin directory.

You may 5 also wish to remove the old path from $PATH

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

gem: --bindir /usr/bin

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

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

Score: 15

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

For example:

gemhome: /usr/local/rubygems

You can also place 2 this file in /etc/gemrc

Alternatively you can set the 1 GEM_HOME env-variable:

$ export GEM_HOME=/tmp/gemtest
$ gem install bundler
$ ls /tmp/gemtest/bin/

Update (10 years later):

Andrey Rodionov below suggest using

gem: --bindir /usr/bin
Score: 2

On OS X, the executable directory is overridden 4 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
  else # generic install

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

Score: 0

To install the executable to a desired directory, the 4 command line option --bindir may be used:

sudo gem install thegemname --bindir /usr/local/rubygems/bin

Tried this 3 option successfully with gem version

For 2 more command line options, run gem install --help on the command 1 line.

More Related questions