Troubles With Rvm and Openssl

troubles with RVM and OpenSSL

Try this:

rvm get head
rvm pkg remove
rvm requirements run # if brew gives you warnings about formulas to install, run "brew install" for each before moving on.

rvm reinstall [the version you need (i.e: 2.0.0)]

rvm can't compile ruby: fails openssl check

Upon closer review, I realized I had an openssl directory (containing version 3) in /usr/local/include and that was on the include path ahead of the directory I specfied with the --with-openssl-dir option.

I fixed it by renaming /usr/local/include/openssl to /usr/local/include/openssl_hideme; after that, the extension compiler found the version I wanted.

I would have guessed that includes on the command line would be put in front of the path, but lesson learned.

Setup RVM, Ruby on Mac OS X Sierra: Unable to require openssl

Well I found a solution to the problem previously described. The following steps outline how it was resolved.

CleanUp

  1. Removed the installation of Homebrew via ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

  2. Removed the installation of RVM via rvm implode

Rebuild

  1. Install Homebrew using ruby -e "$(curl -fsSL
    https://raw.githubusercontent.com/Homebrew/install/master/install)"

  2. Do integrity check on Brew using brew upgrade followed by brew doctor

  3. Install RVM (again!) using \curl -sSL https://get.rvm.io | bash -s stable
  4. Ensure that RVM knows about homebrew through the autolibs option using rvm autolibs homebrew
  5. Setup the environment variables so that we know where the openssl is installed:

    export LDFLAGS=-L/usr/local/opt/openssl/lib

    export CPPFLAGS=-I/usr/local/opt/openssl/include

    export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig

  6. Install ruby via rvm install 2.3.3 --autolibs=homebrew

Check that it Works

  1. Check that the rvm space knows about the OpenSSL certificates using rvm osx-ssl-certs status all. Running this command produced the following output: Certificates for /usr/local/etc/openssl/cert.pem: Up to date.

  2. Install rails via gem install rails

At the last step the installation succeeded and Rails was working (at last!)

Lion: Problem with RVM installing rubies - problem related to openssl

For anyone who should ever have this problem on Lion ... it's some Problem with duplicate headers that come from openssl. You can simply install openssl locally and tell rvm to use that local openssl version.

You can compile opnessl by hand with the prefix /usr/local or simply let rvm do the job:

rvm pkg install openssl

And then tell rvm to link against that version during ruby install:

rvm install 1.9.2 --with-openssl-dir=/path/to/your/home/.rvm/usr

In case you already have a local installation replace with:

rvm install 1.9.2 --with-openssl-dir=/usr/local

DO NOT try what can be read often:

rvm install 1.9.2 -C --with-openssl-dir=/path/to/your/home/.rvm/usr

That does not work.

Trouble with OpenSSL on RHEL 6.3 and all Ruby installers


After far too many hours of research, and learning far more about Linux than I ever cared to, I have narrowed the problem to basic peculiarities of RHEL and OpenSSL and an incorrect assumption made by Ruby (extconf.rb) during installation. The following sites gave me some good clues as to what to look at but I found nothing that put it all together like what I needed.

  • http://www.openssl.org/support/faq.html#BUILD8
  • http://wiki.openssl.org/index.php/Compilation_and_Installation#Fedora_and_Red_Hat
  • http://sachachua.com/blog/2011/04/setting-up-ruby-on-rails-on-a-redhat-enterprise-linux-rackspace-cloud-server/
  • https://web.archive.org/web/20130430124941/https://rvm.io/packages/openssl/

...and not much thanks to a whole bunch of red herrings involving Ruby patches and EC2M. Also, RVM needs to correct their optimism that they have accounted for this with autolibs and should reinstate their previous openssl page.

Basic solution rules

Rule 1

The install of OpenSSL (1.0.1e) created and maintained by yum in /usr/bin cannot be used to compile Ruby's OpenSSL extension correctly -- at least, not on my machine at this time with the latest versions of Ruby (1.9.3-p484, 2.0.0, 2.1.0). RHEL 6.3. I can only surmise that this is due to peculiarities in RedHat's compilation of OpenSSL as hinted at in the OpenSSL FAQ.

Rule 2

I found two old versions (0.9.8) of OpenSSL in /usr/local (in bin + openssl, and ssl/bin) and updating/replacing these got me a bit closer to a solution. For whatever reason, every manual install of OpenSSL 1.0.1f in /usr/local (regardless of bin,openssl,ssl directory arrangement) insisted on putting the libraries in /usr/local/lib64 instead of /usr/local/lib (unless I hacked the Makefile, of course). Ruby's expconf.rb script, however, assumes the OpenSSL libraries will always be in a lib directory. Chasing down this single annoyance (and clash with OpenSSL) was the hardest part of all this. Therefore, to make using an install of OpenSSL in /usr/local work, you must do two things: (1) install Ruby with the --with-openssl-dir switch, and (2) recompile Ruby's OpenSSL extension while also modifying the Makefile to point to lib64 instead of lib. Thus, run something like the following string of commands as root:

ruby-install ruby 1.9.3-p545 -- --with-openssl-dir=/usr/local
cd /usr/local/src/ruby-1.9.3-p545/ext/openssl
ruby extconf.rb

Edit openssl's Makefile to replace something like this:

  libpath = . $(libdir) /usr/local/lib
LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir) -L/usr/local/lib -Wl,-R/usr/local/lib

with something like this:

  libpath = . $(libdir) /usr/local/lib64
LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir) -L/usr/local/lib64 -Wl,-R/usr/local/lib64

Save, and back to the command line:

make
make install

The new Ruby install should now work with OpenSSL properly. As a quick check, I restart my sudo session and then (assuming using chruby):

chruby 1.9
ruby -ropenssl -e "puts OpenSSL::VERSION"

Rule 3

Installing OpenSSL anywhere besides /usr puts the libraries in the expected lib instead of lib64. (Don't ask me why... dunno.) This may be the more maintainable solution as it lets you avoid hacking up the Makefile. This is also the solution RVM uses when running rvm pkg install openssl. Thus, to install both OpenSSL and Ruby (in /opt), you may run commands something like these (I run as sudo bash):

Install OpenSSL:

cd /opt/local
wget http://www.openssl.org/source/openssl-1.0.1f.tar.gz
tar -xzf openssl-1.0.1f.tar.gz
cd openssl-1.0.1f
./config --prefix=/opt/local shared no-asm zlib > openssl_config.log
make > openssl_make.log
make install > openssl_install.log

(The shared switch is required for Ruby to install without error, the no-asm switch helps get rid of a Make warning but does not appear to be required, and zlib and other switches are optional.)

Optional, update openssl certs:

cd /opt/local/ssl
wget http://curl.haxx.se/ca/cacert.pem
mv cacert.pem cert.pem
cd /opt

Back to Ruby:

ruby-install ruby 1.9.3-p545 -- --with-openssl-dir=/opt/local

The new Ruby install should now work with OpenSSL properly. As a quick check, I restart my sudo session and then (assuming using chruby):

chruby 1.9
ruby -ropenssl -e "puts OpenSSL::VERSION"


Related Topics



Leave a reply



Submit