# How to add a non standard Gem path?

**URL:** <https://www.ruby-forum.com/t/how-to-add-a-non-standard-gem-path/222473>\
**Category:** Ruby\
**Created:** [August 29, 2012, 6:17pm UTC](https://www.ruby-forum.com/t/how-to-add-a-non-standard-gem-path/222473 "2012-08-29T18:17:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 29, 2012, 6:17pm UTC](https://www.ruby-forum.com/t/how-to-add-a-non-standard-gem-path/222473/1 "2012-08-29T18:17:37Z")

</div>

Hi, I would like to install some Gems in a custom directory (i.e.  
/usr/local/gems/), so such a directory will have the following  
structure:

ibc@myhost: /usr/local/gems$ ls -l

drwxr-xr-x 2 root root 4,0K ago 29 18:02 bin/  
drwxr-xr-x 2 root root 4,0K ago 29 18:01 cache/  
drwxr-xr-x 2 root root 4,0K ago 29 18:01 doc/  
drwxr-xr-x 6 root root 4,0K ago 29 18:01 gems/  
drwxr-xr-x 2 root root 4,0K ago 29 18:02 specifications/

Once I’ve started a Ruby script, how can I tell the “require” command  
to include my custom Gem directory so “require GEM\_NAME” command looks  
first in /usr/local/gems/gems/_/lib/_ ?

I’ve tryed modifying the Gem.path which by default has this value:

Gem.path  
=\> [“/var/lib/gems/1.9.1”, “/home/ibc/.gem/ruby/1.9.1”]

so I’ve added my directory:

Gem.path.insert 0, “/usr/local/gems”  
Gem.path  
=\> ["/tmp/gems", “/var/lib/gems/1.9.1”, “/home/ibc/.gem/ruby/1.9.1”]

But this does not work, “require” command does not search there.

Any help please?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![SSISSaki\_Baz\_C.SS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@SSISSaki\_Baz\_C.SS\_S](https://www.ruby-forum.com/u/SSISSaki_Baz_C.SS_S)\
**Post date:** [August 29, 2012, 6:32pm UTC](https://www.ruby-forum.com/t/how-to-add-a-non-standard-gem-path/222473/2 "2012-08-29T18:32:13Z")

</div>

Quoting Iñaki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> drwxr-xr-x 2 root root 4,0K ago 29 18:02 specifications/  
> =\> [“/var/lib/gems/1.9.1”, “/home/ibc/.gem/ruby/1.9.1”]
> 
> so I’ve added my directory:
> 
> Gem.path.insert 0, “/usr/local/gems”  
> Gem.path  
> =\> [“/tmp/gems”, “/var/lib/gems/1.9.1”, “/home/ibc/.gem/ruby/1.9.1”]
> 
> But this does not work, “require” command does not search there.

You can try something like this:

$:.unshift yourdirectory

or use rvm ([https://rvm.io/](https://rvm.io/)) ← you can use different ruby versions  
and different gemsets.

or use GEM\_HOME [http://docs.rubygems.org/read/chapter/3](http://docs.rubygems.org/read/chapter/3)

I usually rvm and works very good.

regards  
jordi

---

<div class="post-metadata">

**Author:** ![SSISSaki\_Baz\_C.SS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@SSISSaki\_Baz\_C.SS\_S](https://www.ruby-forum.com/u/SSISSaki_Baz_C.SS_S)\
**Post date:** [August 29, 2012, 6:58pm UTC](https://www.ruby-forum.com/t/how-to-add-a-non-standard-gem-path/222473/3 "2012-08-29T18:58:32Z")

</div>

2012/8/29 Jordi Massaguer P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> You can try something like this:
> 
> $:.unshift yourdirectory

Hi, that is not what I’m looking for. $: is the same as $LOAD\_PATH and  
contains directories in which Ruby searchs for libraries which  
“require” command. This is not the same as adding a new directory for  
Gem search.

In fact, if I show the content of $: (or $LOAD\_PATH) I get this (with  
Ruby 1.9 so rubygem is loaded):

[“/usr/local/lib/site\_ruby/1.9.1”,  
“/usr/local/lib/site\_ruby/1.9.1/x86\_64-linux”,  
“/usr/local/lib/site\_ruby”, “/usr/lib/ruby/vendor\_ruby/1.9.1”,  
“/usr/lib/ruby/vendor\_ruby/1.9.1/x86\_64-linux”,  
“/usr/lib/ruby/vendor\_ruby”, “/usr/lib/ruby/1.9.1”,  
“/usr/lib/ruby/1.9.1/x86\_64-linux”]

There is NOT the Gems directory (and it shouldn’t since it’s not the  
same concept).

This is: I need to install several gems into /usr/local/gems/  
directory and make “require” to look there as now it looks in  
/var/lib/gems/1.9.1/ directory.

> or use rvm ([https://rvm.io/](https://rvm.io/)) ← you can use different ruby versions and  
> different gemsets.

I cannot do that. It is not for something I need in my computer but  
for a library to be published.

> or use GEM\_HOME [http://docs.rubygems.org/read/chapter/3](http://docs.rubygems.org/read/chapter/3)

Yes, I can do this (assuming that I’ve installed the gem “abcd” in  
/usr/local/gems/"):

export GEM\_PATH=/usr/local/gems  
irb -r abcd

It works, but could I load any other Gem installed in the default  
/var/lib/gems/1.9.1/ directory? I’ve tested it right now and got a  
failure and a success, not sure yet… XD

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![SSISSaki\_Baz\_C.SS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@SSISSaki\_Baz\_C.SS\_S](https://www.ruby-forum.com/u/SSISSaki_Baz_C.SS_S)\
**Post date:** [August 29, 2012, 7:01pm UTC](https://www.ruby-forum.com/t/how-to-add-a-non-standard-gem-path/222473/4 "2012-08-29T19:01:29Z")

</div>

2012/8/29 Jordi Massaguer P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> what you are describing sound a lot like using bundler. With bundler you can  
> install gems inside a “vendor” directory and when you start your application  
> with “bundler exec aaa” it loads those. Actually rails uses bundler for  
> managing the gems.
> 
> [http://gembundler.com/](http://gembundler.com/)

It makes lot of sense, I will take a look.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![SSISSaki\_Baz\_C.SS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@SSISSaki\_Baz\_C.SS\_S](https://www.ruby-forum.com/u/SSISSaki_Baz_C.SS_S)\
**Post date:** [August 29, 2012, 7:00pm UTC](https://www.ruby-forum.com/t/how-to-add-a-non-standard-gem-path/222473/5 "2012-08-29T19:00:18Z")

</div>

Quoting Iñaki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> In fact, if I show the content of $: (or $LOAD\_PATH) I get this (with  
> same concept).
> 
> > different gemsets.
> 
> export GEM\_PATH=/usr/local/gems  
> irb -r abcd
> 
> It works, but could I load any other Gem installed in the default  
> /var/lib/gems/1.9.1/ directory? I’ve tested it right now and got a  
> failure and a success, not sure yet… XD
> 
> Thanks a lot.

what you are describing sound a lot like using bundler. With bundler  
you can install gems inside a “vendor” directory and when you start  
your application with “bundler exec aaa” it loads those. Actually  
rails uses bundler for managing the gems.

> **[Gem Bundler – Manage your Ruby gems](http://gembundler.com/)**

regards  
jordi
