Rubygems on Mac OS X

I am having a problem getting gems configured properly on my Mac (OS X
10.4.7), hopefully someone here can help me out. I installed ruby and
ruby gems using the instructions at
http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger.
I am trying to use the XmlSimple gem, but Ruby can’t seem to find it, or
any other gems. I did

$ sudo gem install xml-simple

which seemed to work fine. but then

$ ruby -e “require ‘xmlsimple’”
-e:1:in `require’: no such file to load – xmlsimple (LoadError)
from -e:1

maybe gems is installed wrong?

some other, possibly useful info:
$ ruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.7.0]
$ which ruby
/usr/local/bin/ruby
$ gem env
Rubygems Environment:

  • VERSION: 0.9.0 (0.9.0)
  • INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
  • GEM PATH:
    • /usr/local/lib/ruby/gems/1.8
  • REMOTE SOURCES:

Thanks in advance!
-geoff

Geoff Hulette wrote:

I am having a problem getting gems configured properly on my Mac (OS X
10.4.7), hopefully someone here can help me out. I installed ruby and
ruby gems using the instructions at
http://hivelogic.com/articles/2005/12/01/ruby_rails_lighttpd_mysql_tiger.
I am trying to use the XmlSimple gem, but Ruby can’t seem to find it, or
any other gems. I did

$ sudo gem install xml-simple

which seemed to work fine. but then

$ ruby -e “require ‘xmlsimple’”
-e:1:in `require’: no such file to load – xmlsimple (LoadError)
from -e:1

Rubygems is not loaded with your program. There several ways to
accomplish this. This URL will help:
http://docs.rubygems.org/read/chapter/3#page70.

In a nutshell, you should be able to do this:

$ ruby -e “require ‘rubygems’; require ‘xmlsimple’”

– Jim W.

$ ruby -e “require ‘xmlsimple’”
-e:1:in `require’: no such file to load – xmlsimple (LoadError)
from -e:1

Rubygems is not loaded with your program. There several ways to
accomplish this. This URL will help:
http://docs.rubygems.org/read/chapter/3#page70.

In a nutshell, you should be able to do this:

$ ruby -e “require ‘rubygems’; require ‘xmlsimple’”

– Jim W.

That works, thanks!
-geoff

Try this:

ruby -e “require ‘rubygems’; require ‘xml-simple’”

You have to require rubygems first.

-Ryan

quoth the lists:

Try this:

ruby -e “require ‘rubygems’; require ‘xml-simple’”

You have to require rubygems first.

-Ryan

Sorry to hijack here, but this is an issue that has sort of unsettled me
as I
have seen it come up on this list a few times. Perhaps I am not
understanding
gems fully here, but what if you are writing software to be released to
the
public that relies on a 3rd party library?

Some might have the lib installed from gems and some might have
installed
manually or whatever … so how do you reconcile the two if you must
require
rubygems to use gem installed libs? Why is the gems directory not added
to
the regular include path? Are you required to write code to deal with
this?
How do experienced Ruby devs deal with this issue? Or am I just thick
and it
isn’t an issue at all?

any insight appreciated,

-d

darren kirby [2006-08-13 05:34]:

public that relies on a 3rd party library?

Some might have the lib installed from gems and some might have installed
manually or whatever … so how do you reconcile the two if you must require
rubygems to use gem installed libs? Why is the gems directory not added to
the regular include path? Are you required to write code to deal with this?
How do experienced Ruby devs deal with this issue? Or am I just thick and it
isn’t an issue at all?

any insight appreciated,

export RUBYOPT=rubygems

The you can use “require” to load both gem-libraries and
non-gem-libraries.

Regards,
Tilman

On Aug 12, 2006, at 11:43 AM, Geoff Hulette wrote:

    from -e:1

maybe gems is installed wrong?

I do:
require ‘rubygems’
require_gem ‘<gem_name>’

Which seems to work just fine.


The folly of mistaking a paradox for a discovery, a metaphor for a
proof, a torrent of verbiage for a spring of capital truths, and
oneself for an oracle, is inborn in us.
-Paul Valery, poet and philosopher (1871-1945)

quoth the Tilman S.:

export RUBYOPT=rubygems

The you can use “require” to load both gem-libraries and
non-gem-libraries.

Regards,
Tilman

Thanks Tilman,
That’s what I was looking for…

-d

You can also do

ruby -rrubygems -e “require ‘xmlsimple’”

which will “require ‘rubygems’” for you (because of the “-rrubygems”).
Read up on -r if it doesn’t click for you.

Cheers,

M.T.

[email protected] [2006-08-14 00:04]:

isn’t an issue at all?

any insight appreciated,

export RUBYOPT=rubygems

Of course, this isn’t such a great solution from inside a library,
However, it’s not too hard.

If you are the author of some library:

cat <>README
If you’re using rubygems, please export RUBYOPT=rubygems.
EOF

Done.

Regards,
Tilman

On Sun, 13 Aug 2006, Tilman S. wrote:

Some might have the lib installed from gems and some might have installed
manually or whatever … so how do you reconcile the two if you must require
rubygems to use gem installed libs? Why is the gems directory not added to
the regular include path? Are you required to write code to deal with this?
How do experienced Ruby devs deal with this issue? Or am I just thick and it
isn’t an issue at all?

any insight appreciated,

export RUBYOPT=rubygems

Of course, this isn’t such a great solution from inside a library,
However, it’s not too hard.

begin
require ‘rubygems’
rescue LoadError
end

quoth the Tilman S.:

Done.

I guess it would be bad form to go setting env variables on someone’s
system
from within a lib…

So you could do:

begin
require ‘rubygems’
rescue LoadError
end
require ‘libfoo’

And it would load ‘libfoo’ either through gems, if present, or regularly
if
not? Is that right?

Regards,
Tilman

-d

darren kirby [2006-08-14 05:57]:

EOF

Done.

I guess it would be bad form to go setting env variables on someone’s system
from within a lib…

Of course. That’s why you would tell your fellow users to please export
RUBYOPT=rubygems. So you don’t have to change your code.

I’m sure this is documented somewhere, too.

Regards,
Tilman

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs