Forum: Ruby Mac OS 10.8.2 and openssl

Posted by Dr. Hegewald (Guest)
on 2013-02-27 10:40
(Received via mailing list)
Hi everybody,
I just installed the current ruby 2.0.0p0 on a Mac OS 10.8.2.

$ ruby --version
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]

Then I want to install my gems as usual:
$ gem install terminal-notifier
ERROR:  Loading command: install (LoadError)
  cannot load such file -- openssl
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass

I remember reading that ruby 2.0 is not using the SSL gem anymore, but 
the system installed openssl instead. I guess this is the problem here, 
but there is an openssl available in my $PATH:

$ which openssl
/usr/bin/openssl

I guess this is an FAQ, but could not find anything related. What is the 
prefereed way to fix this? Do I have to explicitly tell ruby where the 
openssl lives?

Many TIA,
Jan Hegewald
Posted by Dr. Hegewald (Guest)
on 2013-02-27 10:43
(Received via mailing list)
On 27.02.2013, at 10:32, Dr. Hegewald <hegewald@irmb.tu-bs.de> wrote:

> $ which openssl
> /usr/bin/openssl

Sorry, forgot to add openssl version:

$ openssl version
OpenSSL 0.9.8r 8 Feb 2011

Cheers,
Jan Hegewald
Posted by Carlo E. Prelz (Guest)
on 2013-02-27 10:48
(Received via mailing list)
Subject: Mac OS 10.8.2 and openssl
  Date: mer 27 feb 13 06:32:24 +0900

Quoting Dr. Hegewald (hegewald@irmb.tu-bs.de):

> Then I want to install my gems as usual:
> $ gem install terminal-notifier
> ERROR:  Loading command: install (LoadError)
>   cannot load such file -- openssl
> ERROR:  While executing gem ... (NoMethodError)
>     undefined method `invoke_with_build_args' for nil:NilClass

If you compile from source, try to go to <path_of_source>/ext/openssl,
and type this:

ruby extconf.rb
make
sudo make install

Does the process complete without errors? If so, you should at this
point try again the gem loading command.

Carlo
Posted by Dr. Hegewald (Guest)
on 2013-02-27 11:19
(Received via mailing list)
Hi Carlo and all,

On 27.02.2013, at 10:45, Carlo E. Prelz <fluido@fluido.as> wrote:

>>    undefined method `invoke_with_build_args' for nil:NilClass
>
> If you compile from source, try to go to <path_of_source>/ext/openssl,
> and type this:
>
> ruby extconf.rb

that does not seem to work:

$ ruby extconf.rb
checking for t_open() in -lnsl... no
checking for socket() in -lsocket... no
checking for assert.h... yes
checking for openssl/ssl.h... yes
checking for OpenSSL_add_all_digests() in -lcrypto... yes
checking for SSL_library_init() in -lssl... yes
checking for openssl/conf_api.h... yes
checking for SSL_library_init() in openssl/ssl.h with 
-Werror=deprecated-declarations... no
extconf.rb:62:in `<main>': Ignore OpenSSL broken by Apple. 
(RuntimeError)
Please use another openssl. (e.g. using `configure 
--with-openssl-dir=/path/to/openssl')

So do I really have to install another openssl? If I do so, can I 
exclude it from my $PATH, as it is set via --with-openssl-dir ?

Cheers,
Jan
Posted by Carlo E. Prelz (Guest)
on 2013-02-27 11:46
(Received via mailing list)
Subject: Re: Mac OS 10.8.2 and openssl
  Date: mer 27 feb 13 07:18:50 +0900

Quoting Dr. Hegewald (hegewald@irmb.tu-bs.de):

> that does not seem to work:

So that's the reason. Of course if you download openssl (latest is

http://www.openssl.org/source/openssl-1.0.1e.tar.gz

), compile and install it, it *should* be installed under
/usr/local. Then, when you call extconf.rb you *should* pick it in
preference of the default Apple version. And compilation of the Ruby
openssl extensions *should* proceed OK.

Of course, I cannot guarantee anything about this as I am too poor to
own a mac ;-). Also, there is another caveat: I have no idea
whatsoever if the other apps in MacOS will be happy about the
change. You could open a can of worms...

The other path is to learn how to install Openssl in another directory
(read the INSTALL file), and then include the path where the new
openssl.pc file is stored after you run make install at the beginning
of the PKG_CONFIG_PATH shell variable, before executing extconf.rb.
This way, you will keep two separate copies, and Ruby will always use
the newer one, while the rest will still find the old one.

Good luck!

Carlo
Posted by Dr. Hegewald (Guest)
on 2013-02-27 11:47
(Received via mailing list)
Hi all,

On 27.02.2013, at 11:18, "Dr. Hegewald" <hegewald@irmb.tu-bs.de> wrote:
>
> extconf.rb:62:in `<main>': Ignore OpenSSL broken by Apple. (RuntimeError)
> Please use another openssl. (e.g. using `configure 
--with-openssl-dir=/path/to/openssl')

OK, I installed another openssl (OpenSSL 1.0.1e 11 Feb 2013) and tried 
to tell configure about it using the above mentioned flag:

$ ./configure --with-openssl-dir=/Users/me/bin/openssl-1.0.1e-bin/bin 
--prefix=/Users/me/bin/ruby-2.0.0-p0-bin
configure: WARNING: unrecognized options: --with-openssl-dir

Huh? What is that?

Cheers,
Jan
Posted by Dr. Hegewald (Guest)
on 2013-02-27 12:05
(Received via mailing list)
Hi Carlo and all,

On 27.02.2013, at 11:45, "Carlo E. Prelz" <fluido@fluido.as> wrote:

> http://www.openssl.org/source/openssl-1.0.1e.tar.gz
>
> ), compile and install it, it *should* be installed under
> /usr/local. Then, when you call extconf.rb you *should* pick it in
> preference of the default Apple version. And compilation of the Ruby
> openssl extensions *should* proceed OK.

No, I do not want to change the default openssl. This would require 
admin access and probably messes with other things.

>
> Of course, I cannot guarantee anything about this as I am too poor to
> own a mac ;-). Also, there is another caveat: I have no idea
> whatsoever if the other apps in MacOS will be happy about the
> change. You could open a can of worms

(-:

>
> The other path is to learn how to install Openssl in another directory

I did that, see my previous mail.

> then include the path where the new
> openssl.pc file is stored after you run make install at the beginning
> of the PKG_CONFIG_PATH shell variable, before executing extconf.rb.

Sorry, this description is to compact for me to follow. Do I still need 
to pass --with-openssl-dir to configure?

Many thanks,
Jan
Posted by Carlo E. Prelz (Guest)
on 2013-02-27 14:33
(Received via mailing list)
Subject: Re: Mac OS 10.8.2 and openssl
  Date: mer 27 feb 13 07:58:37 +0900

Quoting Dr. Hegewald (hegewald@irmb.tu-bs.de):

> > The other path is to learn how to install Openssl in another directory
>
> I did that, see my previous mail.
>
> > then include the path where the new
> > openssl.pc file is stored after you run make install at the beginning
> > of the PKG_CONFIG_PATH shell variable, before executing extconf.rb.
>
> Sorry, this description is to compact for me to follow. Do I still
> need to pass --with-openssl-dir to configure?

This is a bit off-topic for this list, so I will have to be concise.

Say you want to install openssl in /path/to/install:

1)
mkdir -p /path/to/install

2) (from the source of openssl)
./Configure darwin64-x86_64-cc --prefix=/path/to/install 
--openssldir=/path/to/install/openssl/
make
make install

3) (from ..../ruby/ext/openssl)
export PKG_CONFIG_PATH=/path/to/install/lib/pkgconfig:$PKG_CONFIG_PATH
make clean
ruby extconf.rb
make
make install

If this fails, you should seek help from someone who knows more than I
do about macos.

Carlo
Posted by Dr. Hegewald (Guest)
on 2013-02-27 15:20
(Received via mailing list)
Hi Carlo and all,

On 27.02.2013, at 14:33, "Carlo E. Prelz" <fluido@fluido.as> wrote:

>>> openssl.pc file is stored after you run make install at the beginning
>>> of the PKG_CONFIG_PATH shell variable, before executing extconf.rb.
>>
>> Sorry, this description is to compact for me to follow. Do I still
>> need to pass --with-openssl-dir to configure?
>
> This is a bit off-topic for this list, so I will have to be concise.

Ups, do you know a better list for questions about compiling ruby?

>
> Say you want to install openssl in /path/to/install:

openssl compiles and installed just fine. It is OpenSSL 1.0.1e 11 Feb 
2013, as I wrote previously.

> 3) (from ..../ruby/ext/openssl)
> export PKG_CONFIG_PATH=/path/to/install/lib/pkgconfig:$PKG_CONFIG_PATH
> make clean
> ruby extconf.rb

This command fails with the same error as before,

extconf.rb:62:in `<main>': Ignore OpenSSL broken by Apple. 
(RuntimeError)
Please use another openssl. (e.g. using `configure 
--with-openssl-dir=/path/to/openssl')

And the suggested solution does not work, as the ruby configure does not 
understand the --with-openssl-dir flag.

Many thanks for your efforts here Carlo. But I think I have to go back 
to ruby 1.9.3 until I get new input on the issue.

Cheers,
Jan Hegewald
Posted by Carlo E. Prelz (Guest)
on 2013-02-27 16:09
(Received via mailing list)
Subject: Re: Mac OS 10.8.2 and openssl
  Date: mer 27 feb 13 11:19:26 +0900

Quoting Dr. Hegewald (hegewald@irmb.tu-bs.de):

> > 3) (from ..../ruby/ext/openssl)
> > export PKG_CONFIG_PATH=/path/to/install/lib/pkgconfig:$PKG_CONFIG_PATH
> > make clean
> > ruby extconf.rb
>
> This command fails with the same error as before,

Are you sure you executed the export command correctly? What do you
get if you type

echo $PKG_CONFIG_PATH

? And if you type

ls -al /path/to/install/lib/pkgconfig

? Also, the contents of the mkmf.log file may be useful.

> Many thanks for your efforts here Carlo. But I think I have to go
> back to ruby 1.9.3 until I get new input on the issue.

Maybe... Somebody who regularly uses Ruby under Mac will eventually
offer the right solution.

Carlo
Posted by Jeremy Kemper (Guest)
on 2013-02-27 16:28
(Received via mailing list)
On Wed, Feb 27, 2013 at 3:32 AM, Dr. Hegewald <hegewald@irmb.tu-bs.de> 
wrote:
> ERROR:  Loading command: install (LoadError)
>         cannot load such file -- openssl

Take a look at ruby-build. It handles the ins & outs of compiling Ruby
on the Mac, including OpenSSL:
https://github.com/sstephenson/ruby-build

Otherwise, you'll need to build openssl, configure Ruby
--with-openssl-dir, and fetch your own root CA certificates. Big song
and dance.

RVM can wrap this up for you, too: https://rvm.io/rvm/install/

(I wish Ruby kept support for Apple's patched OpenSSL, even though
it's deprecated and broken.)
Posted by Hassan Schroeder (Guest)
on 2013-02-27 16:42
(Received via mailing list)
On Wed, Feb 27, 2013 at 7:27 AM, Jeremy Kemper <jeremy@bitsweat.net> 
wrote:

> RVM can wrap this up for you, too: https://rvm.io/rvm/install/

Yep, I just installed Ruby 2.0 using rvm on a Mac (10.7.5) that has
the old Apple 'OpenSSL 0.9.8r 8 Feb 2011' with no problem.
Posted by guillermo haas-thompson (memoht)
on 2013-02-27 19:08
I have spent the last couple of days struggling to get Ruby 2.0 to
compile under Mac OS X 10.8.2 using first RVM and as of last night 
Chruby. I
have come to realize the full extent of this openssl issue after trying
to follow the instructions at 
https://github.com/postmodern/chruby/wiki/MRI

• I am using Homebrew so I installed openssl and am also having the
issue that trying to use --with-openssl-dir option on ./configure is not
working.

• Compiling Ruby 2.0 without this works, but then I cannot install
Bundler 1.3
because it can't find openssl, so I am dead in the water at that point.

I would also appreciate some clear syntax and steps to compile Ruby 2.0
properly under Mac OS X, of course in my case using Homebrew and Chruby.
This is turning out to be much harder than I thought and from what I see
has been a known issue for some months.

Any help or link to a site would be appreciated. I have Googled till my 
eyes bled and unfortunately the best site I found was mostly in 
Japanese.
Posted by Jeremy Kemper (Guest)
on 2013-02-27 23:55
(Received via mailing list)
On Wed, Feb 27, 2013 at 9:41 AM, Hassan Schroeder
<hassan.schroeder@gmail.com> wrote:
> Yep, I just installed Ruby 2.0 using rvm on a Mac (10.7.5) that has
> the old Apple 'OpenSSL 0.9.8r 8 Feb 2011' with no problem.

10.7.x does not have this issue.
Posted by Jeremy Kemper (Guest)
on 2013-02-27 23:58
(Received via mailing list)
On Wed, Feb 27, 2013 at 12:09 PM, guillermo haas-thompson
<lists@ruby-forum.com> wrote:
> I would also appreciate some clear syntax and steps to compile Ruby 2.0
> properly under Mac OS X, of course in my case using Homebrew and Chruby.
> This is turning out to be much harder than I thought and from what I see
> has been a known issue for some months.

chruby works well with ruby-build.

Use ruby-build to install 2.0.0-p0. It'll handle the OpenSSL setup.

https://github.com/sstephenson/ruby-build#readme
Posted by guillermo haas-thompson (memoht)
on 2013-02-28 00:19
Jeremy Kemper wrote in post #1099453:
> On Wed, Feb 27, 2013 at 12:09 PM, guillermo haas-thompson
> <lists@ruby-forum.com> wrote:
>> I would also appreciate some clear syntax and steps to compile Ruby 2.0
>> properly under Mac OS X, of course in my case using Homebrew and Chruby.
>> This is turning out to be much harder than I thought and from what I see
>> has been a known issue for some months.
>
> chruby works well with ruby-build.
>
> Use ruby-build to install 2.0.0-p0. It'll handle the OpenSSL setup.
>
> https://github.com/sstephenson/ruby-build#readme

I have been reading around and it looks like there were still problems
even when using ruby-build
(https://github.com/sstephenson/ruby-build/issues/305) and so it seems
like maybe I should uninstall my Homebrew openssl beforehand if I decide
to give it a whirl with ruby-build. I was hoping to be able to avoid
that and just compile from source.
Posted by Hassan Schroeder (Guest)
on 2013-02-28 00:30
(Received via mailing list)
On Wed, Feb 27, 2013 at 2:55 PM, Jeremy Kemper <jeremy@bitsweat.net> 
wrote:

> 10.7.x does not have this issue.

So what exactly *is* the issue, if not the version of OpenSSL?
Posted by guillermo haas-thompson (memoht)
on 2013-02-28 01:15
To recap:
• I installed openssl via Homebrew
• I completely removed RVM and went with Chruby
• Was following the instructions for 2.0.0 at
https://github.com/postmodern/chruby/wiki/MRI

In my comment above, where I reference ruby-build issue #305, a user
under that thread said: "configure: WARNING: unrecognized options:
--with-openssl-dir
Confusingly, this is normal. Ruby doesn't recognize the option, but the
openssl extension does."

So, taking a leap of faith and combining that with the Chruby wiki, the
final command that appears to have worked for me is:
./configure --prefix=/opt/rubies/ruby-2.0.0-p0 --with-openssl-dir=`brew
--prefix openssl`   --with-readline-dir=`brew --prefix readline`
--with-yaml-dir=`brew --prefix libyaml`  --with-gdbm-dir=`brew --prefix
gdbm`  --with-libffi-dir=`brew  --prefix libffi`

The trick is to completely ignore the error message spit back from
./configure about not knowing what any of these --with options are and
go ahead with the rest of the instructions on building and installing
the makefile.

Finally, I just cd'd into my app with Ruby 2.0.0 and was able to "gem
install bundler" without getting an openssl failure. First time I tried 
to bundle my gems though, I did get an SSL error.

And finally:
• Got an email back from Postmodern with this lifesaver 
https://github.com/raggi/openssl-osx-ca#readme
Posted by Dr. Hegewald (Guest)
on 2013-02-28 09:09
(Received via mailing list)
On 27.02.2013, at 16:03, Carlo E. Prelz <fluido@fluido.as> wrote:

>> This command fails with the same error as before,
>
> Are you sure you executed the export command correctly?

I guess it is OK:

$ ls -l $PKG_CONFIG_PATH
total 24
-rw-r--r--  1 me  we  288 27 Feb 11:35 libcrypto.pc
-rw-r--r--  1 me  we  303 27 Feb 11:35 libssl.pc
-rw-r--r--  1 me  we  313 27 Feb 11:35 openssl.pc


>
> ? Also, the contents of the mkmf.log file may be useful.

This is the openssl/mkmf.log:

Ignore OpenSSL broken by Apple.
Please use another openssl. (e.g. using `configure 
--with-openssl-dir=/path/to/openssl')
Failed to configure openssl. It will not be installed.

Cheers,
Jan
Posted by Carlo E. Prelz (Guest)
on 2013-02-28 09:57
(Received via mailing list)
Subject: Re: Mac OS 10.8.2 and openssl
  Date: gio 28 feb 13 05:09:24 +0900

Quoting Dr. Hegewald (hegewald@irmb.tu-bs.de):

> > ? Also, the contents of the mkmf.log file may be useful.
>
> This is the openssl/mkmf.log:
>
> Ignore OpenSSL broken by Apple.
> Please use another openssl. (e.g. using `configure 
--with-openssl-dir=/path/to/openssl')
> Failed to configure openssl. It will not be installed.

Only? If so, your ruby source must be damaged. There should be a lot of
other stuff in the file.

Try to execute this short script, AFTER SETTING PKG_CONFIG_PATH as I
wrote yesterday:

--8<----8<----8<----8<----8<----8<----8<----8<----8<--
require 'mkmf'
p pkg_config('openssl')
p 
have_func('SSL_library_init()','openssl/ssl.h','-Werror=deprecated-declarations')
p have_header('openssl/ssl.h',nil,'-Werror=deprecated-declarations')
--8<----8<----8<----8<----8<----8<----8<----8<----8<--

What is the output, and what is the entire content of the resulting
mkmf.log? (Note that my file is 50 lines long).

The point is that, after executing pkg_config, you should only access
your new copy of openssl, which should pass that test. At least this
is what happens here.

Carlo
Posted by Dr. Hegewald (Guest)
on 2013-02-28 10:25
(Received via mailing list)
On 28.02.2013, at 09:56, "Carlo E. Prelz" <fluido@fluido.as> wrote:

>> Please use another openssl. (e.g. using `configure 
--with-openssl-dir=/path/to/openssl')
>> Failed to configure openssl. It will not be installed.
>
> Only? If so, your ruby source must be damaged. There should be a lot of
> other stuff in the file.

It is from ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.bz2 
and ruby compiles and runs from this source (though with out openssl).

But I think I got it working eventually:

Reading the suggestions and linked discussions the the others have 
provided, I gave the --with-openssl-dir flag another chance (as it seems 
still to be used despite of the warning). Now I tried different path 
variants to point to my new openssl install. It seems so succeed when 
using the dir above the openssl bin dir. Previously I only tried the 
path to the binary and the path to its containing dir:

ls /Users/me/bin/openssl-1.0.1e-bin
bin  include  lib  ssl

cd ruby-2.0.0-p0-src
./configure --with-openssl-dir=/Users/me/bin/openssl-1.0.1e-bin 
--prefix=/Users/me/bin/ruby-2.0.0-p0-bin
make install

and now I could install gems with e.g.
gem install terminal-notifier

So I guess the openssl stuff is configured fine now.

Cheers and many thanks to all for the very useful input!

Jan Hegewald
Posted by Jeremy Kemper (Guest)
on 2013-02-28 23:01
(Received via mailing list)
On Wed, Feb 27, 2013 at 4:21 PM, Hassan Schroeder
<hassan.schroeder@gmail.com> wrote:
> On Wed, Feb 27, 2013 at 2:55 PM, Jeremy Kemper <jeremy@bitsweat.net> wrote:
>
>> 10.7.x does not have this issue.
>
> So what exactly *is* the issue, if not the version of OpenSSL?

10.8.x ships a patched OpenSSL that Ruby won't compile with.
Posted by Bill C. (bill_c)
on 2013-05-18 01:27
Hey, I have a radical and crazy idea.

How about, instead of having every single person who wants to install 
ruby and gems on OSX have to jump through this stupid series of 
ridiculous hoops, the relatively few ruby DEVELOPERS actually fix the 
build configuration (for OS X and others as well)? The man-hours spent 
this way are all upside down. Fix it at the head, not at the tail. This 
kind of hopeless head-banging by all of us is an idiotic expectation.

The fact that "--with-openssl-dir" apparently throws meaningless errors 
(or are they meaningful, and how the hell are we supposed to know?) 
proves that ruby devs aren't minding the store.

Someone(s) who _understand(s)_ the "configure" and "automake" setup 
should actually provide documentation for --with-openssl-dir and 
--with-out-tcl and --with-out-tk and the dozens of other parameters that 
cause lots of errors that the build plows right through. Use these 
parameters at all and have the system bark at you. And expect them to 
have no effect as well, in my experience.

A ruby USER shouldn't have to know everything that the ruby DEVS do, but 
we are getting closer to it with every release. This is only one more 
thing to really make it a pain in the neck for every OSX ruby user out 
here. It almost feels like ruby devs want to make ruby such a pain to 
build or install that the rest of us will give up on it.

Better yet, Apple, how about releasing ruby 2.0 with your next iteration 
of OS X? OK, now I'm obviously hallucinating.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.