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:
     - http://gems.rubyforge.org

Thanks in advance!
-geoff

···

--
Posted via http://www.ruby-forum.com/.

Try this:

ruby -e "require 'rubygems'; require 'xml-simple'"

You have to require rubygems first.

-Ryan

···

On Aug 12, 2006, at 1:43 PM, 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
Dan Benjamin.
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:
     - http://gems.rubyforge.org

Thanks in advance!
-geoff

--
Posted via http://www.ruby-forum.com/\.

I do:
require 'rubygems'
require_gem '<gem_name>'

Which seems to work just fine.

···

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

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?

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

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
Dan Benjamin.
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 Weirich

···

--
Posted via http://www.ruby-forum.com/\.

$ 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 Weirich

That works, thanks!
-geoff

···

--
Posted via http://www.ruby-forum.com/\.

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 :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

quoth the lists:
> Try this:
>
> ruby -e "require 'rubygems'; require 'xml-simple'"
>
> You have to require rubygems first.

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,

export RUBYOPT=rubygems

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

Regards,
Tilman

···

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

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.

quoth the Tilman Sauerbeck:
<snip>

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

···

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

···

On Sun, 13 Aug 2006, Tilman Sauerbeck 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

khaines@enigo.com [2006-08-14 00:04]:

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

If you are the author of some library:

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

Done.

Regards,
Tilman

···

On Sun, 13 Aug 2006, Tilman Sauerbeck wrote:

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

quoth the Tilman Sauerbeck:

> >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 <<EOF >>README
If you're using rubygems, please export RUBYOPT=rubygems.
EOF

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 :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

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

quoth the Tilman Sauerbeck:
> > >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 <<EOF >>README
> If you're using rubygems, please export RUBYOPT=rubygems.
> 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

···

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?