Dan Zwell
4/29/2007 10:57:00 PM
jzakiya wrote:
> No problem ro run gem as root:
>
> [root]# gem -v
> 0.9.2
>
> But if I try to run gem from my [home], problems:
>
> [home]$ gem -v (or /usr/bin/gem -v)
> /usr/bin/gem:9:in `require': no such file to load -- rubygems
> (LoadError)
> from /usr/bin/gem:9
>
> I put a symbolic link in my /usr/local/bin; ln -s /usr/bin/gem gem
> but that wouldn't let me run gem from [home] either.
>
> Is this a rubygems problem?
> Do I have to put a separate copy of rubygems in my [home] dir for it
> to work there?
>
> I also looked into the rubyconfig.rb file, but it didn't seem that
> needed any change.
>
> HELP!
>
> jz
>
jz,
First off, it might be useful to note whether root and your user account
are actually running the same version of gem by running "which gem" as
user and as root.
But more importantly, it looks like when you are running "gem", it's
trying to include a file, "rubygems.rb", that it can't find. I would
guess your load paths aren't configured correctly. I'll suggest a
solution, but there's probably a better way to do this. My way feels a
little (okay, a lot) hackish:
I want to add a certain directory to my include path, and I don't ever
want to have to worry about doing it on the command line or modifying my
files. So:
$ ./somescript.rb
is the same as
$ ruby ./somescript.rb
right?
We want to use the -I option to add a directory to the load path. So:
$ ruby ./somescript.rb -I/usr/lib/ruby/site
But I still want to be able to run it without explicitly typing "ruby".
And I don't want to start each of my scripts with #!/usr/bin/ruby
-I/my/load/path, because that would be cumbersome.
So I continue to start the files with #!/usr/bin/env ruby
but I create a script in $HOME/bin (which is before /usr/bin in my path,
so $HOME/bin/ruby gets called, not /usr/bin/ruby). The script only says:
#!/bin/bash
exec /usr/bin/ruby -I/my/load/path "$@"
(Of course, replace /usr/bin/ruby with the path to the executable that
you want to run.) That way, every time you start a file with
#!/usr/bin/env ruby, the right (eventually) executable gets called with
an argument that tells it where to look for include files. You'll need
to find this path on your own system, as it's different on different
distros. I'd start with "locate rubygems.rb".
Good luck, I hope this wasn't too confusing. If anybody reading this has
a really clean solution (like an environment variable that I don't know
about), I'd love to hear about it.
Dan