Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can "gem install" be configured to install executables outside /usr/bin/ by default?

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)

like image 528
dbr Avatar asked Dec 02 '08 09:12

dbr


People also ask

Where does gem get installed?

Finding libraries The main place where libraries are hosted is RubyGems.org, a public repository of gems that can be searched and installed onto your machine. You may browse and search for gems using the RubyGems website, or use the gem command. Using gem search -r , you can search RubyGems' repository.

What is a gem install?

gem install , in its simplest form, does something kind of like this. It grabs the gem and puts its files into a special directory on your system. You can see where gem install will install your gems if you run gem environment (look for the INSTALLATION DIRECTORY: line):

Where do RubyGems get installed?

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/. gem/ruby/1.9. 1 . The commands provided by the gems you installed will end up in ~/.


3 Answers

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/. If you don't do this, then uninstalling or updating a gem will not remove the binary from the original bin directory.

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

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).

like image 194
BryanH Avatar answered Nov 29 '22 21:11

BryanH


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

Alternatively you can set the GEM_HOME env-variable:

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

Update (10 years later):

Andrey Rodionov below suggest using

gem: --bindir /usr/bin
like image 22
csl Avatar answered Nov 29 '22 20:11

csl


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?

like image 32
dbr Avatar answered Nov 29 '22 21:11

dbr