Joyce Babu Joyce Babu - 2 years ago 92
Ruby Question

How to require ruby gem from a specific location?

I am new to ruby, and is trying to write a git hook in ruby. I want to use the rugged gem in my script. The gem is already available in

as part of GitLab installation (Files List). How can I require that gem in my script?

I have tried
$LOAD_PATH.unshift "/opt/gitlab/embedded/service/gem/ruby/2.1.0/"
and then
require "rugged"
, as mentioned in another stackoverflow answer, but it did not work.

Answer Source

Look carefully at how $LOAD_PATH is configured for each gem after you include it. Normally it's the full path to where the base gemname.rb is located, like in your case where rugged.rb is.

The way the $LOAD_PATH works is it scans through that list looking for rugged.rb and if it doesn't find it, moves on to the next possible location. You're specifying a directory which doesn't have that, so find the right path and fill that in, and you should be good.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download