Installing openssl in ruby / rbenv
Asked Answered
C

7

29

I need to use openssl in ruby. How should I install the same? I've installed ruby through rbenv, and am using ubuntu 12.04.

kprakasam@ubuntu:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

kprakasam@ubuntu:~$ irb
irb(main):001:0> require 'openssl'
LoadError: no such file to load -- openssl
    from /home/kprakasam/.rbenv/versions/1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/kprakasam/.rbenv/versions/1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from (irb):1
    from /home/kprakasam/.rbenv/versions/1.9.2-p180/bin/irb:12:in `<main>'
Combustor answered 20/6, 2012 at 18:43 Comment(2)
I think you have to compile ruby with opensslDecadent
sudo apt-get -y build-essential install zlib1g-dev libreadline-dev libssl-dev libcurl4-openssl-dev than install ruby again with rbenv, and you will have openssl supportThinkable
C
24

openssl needs to be installed on your local machine.

You then need to compile Ruby with openssl support, which is achieved via the --with-openssl-dir command-line switch.

Maybe this will help you.

Colley answered 20/6, 2012 at 18:51 Comment(1)
Then I face the following error - Error running '__rvm_make -j4'Heaven
A
45

For Mac OSX this is what saved me:

RUBY_CONFIGURE_OPTS=--with-openssl-dir=<openssl install dir> rbenv install

From the Ruby build wiki

But.. how to find the openssl install dir?:

$ brew list openssl
/usr/local/Cellar/openssl/1.0.2d_1/bin/c_rehash
/usr/local/Cellar/openssl/1.0.2d_1/bin/openssl
...

Then the openssl install dir is:

/usr/local/Cellar/openssl/1.0.2d_1/

And the ruby installation command ends as this:

RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/local/Cellar/openssl/1.0.2d_1/ rbenv install
Acetone answered 5/4, 2016 at 7:28 Comment(6)
I'll add that my compilation error on OSX mentioned two versions of openssl, I then removed all versions of openssl from brew (uninstall and prune) and reinstalled openssl. Then compiling worked with ruby-install ruby 2.5.1 -- --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2o_1/.Mestee
Fixes /tmp/ruby-build.20190501225018.25089/ruby-2.6.3/lib/rubygems/core_ext/kernel_require.rb:54:in `require': libssl.so.1.0.0: cannot open shared object file: No such file or directory - /tmp/ruby-build.20190501225018.25089/ruby-2.6.3/.ext/x86_64-linux/openssl.so (LoadError) on Debian 9 as wellFascine
Thank you! also fixes "Failed to configure openssl. It will not be installed."Bobwhite
brew --prefix [email protected] can be used to get the openssl path, i.e. RUBY_CONFIGURE_OPTS=--with-openssl-dir=$(brew --prefix [email protected])Specht
Unrecognised command, it just opens help on how to use flags. I copied the command exactly.Shavon
This worked for me on my jekyll install which just started complaining when I tried to update the gems via the GitHub-pages gem. jekyll is using ruby 2.7.4, so I had to install [email protected] using Homebrew and then re-install ruby with that via RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]" rbenv install 2.7.4Pulido
C
24

openssl needs to be installed on your local machine.

You then need to compile Ruby with openssl support, which is achieved via the --with-openssl-dir command-line switch.

Maybe this will help you.

Colley answered 20/6, 2012 at 18:51 Comment(1)
Then I face the following error - Error running '__rvm_make -j4'Heaven
C
17

Ubuntu

(and other linux distros)

$ # Display the installation directory:
$ openssl version -d
OPENSSLDIR: "/usr/lib/ssl"

$ # May need to uninstall the previous installation:
$ rbenv uninstall 3.1.2
rbenv: remove /home/aidan/.rbenv/versions/3.1.2? [yN] Y

$ # Then reinstall (using the dir from the first step)
$ RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/lib/ssl rbenv install 3.1.2 
Installing ruby-3.1.2...
Installed ruby-3.1.2 to /home/aidan/.rbenv/versions/3.1.2
Cassimere answered 5/5, 2022 at 23:41 Comment(1)
Thanks. For ruby 2.4.4 the dir of first command did not work. I had to do RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/share/rvm/usr rbenv install 2.4.4 insteadKaitlynkaitlynn
C
11

First, install openssl:

sudo apt-get -y install build-essential zlib1g-dev libreadline-dev libssl-dev libcurl4-openssl-dev

Afterwards, recompile Ruby.

Note: Only fixing the comment from @Nebojsa above

Clie answered 17/9, 2013 at 21:50 Comment(2)
This worked for me when installing ruby-2.0.0-p451 from source onto Ubuntu-Saucy 13.10.Louden
I have upgraded my ubuntu to version 20.04.1 and my ruby stopped working. Using this command and reinstalling the ruby versions on my rbenv did the trick. Thanks!Sinuosity
M
6

This might help you: Rails: cannot load such file — openssl.

Manns answered 20/6, 2012 at 19:4 Comment(1)
This is useful if you're using RVM. See the accepted answer if using RBENV.Osteoarthritis
J
4

EDIT: Please note that this answer may be out of date. The issue in question was resolved in v0.8.1.


After reading multiple answers to this question, I managed to get it working on macOS 10.15 using the following commands:

brew install rbenv/tap/[email protected]
OPENSSL_1_0_DIR=$(brew --prefix rbenv/tap/[email protected])

export CPPFLAGS=-I${OPENSSL_1_0_DIR}/include
export LDFLAGS=-L${OPENSSL_1_0_DIR}/lib

ruby-install ruby 2.2.10 -- --with-openssl-dir=${OPENSSL_1_0_DIR}
Jingoism answered 20/5, 2020 at 14:34 Comment(0)
L
0

I am on an M2 mac with two versions of openssl installed via Brew (1.1 & 3).

I set an env var for the --with-openssl-dir with version 1.1's path.

fish:

set -gx RUBY_CONFIGURE_OPTS "--with-openssl-dir=/opt/homebrew/opt/[email protected]"

bash/zsh:

export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"

The build succeeded after the export for me.

Note: That I also exported corresponding CPPFLAGS & LDFLAGS for the compiler.

export LDFLAGS=-L/opt/homebrew/opt/[email protected]
export CPPFLAGS=-I/opt/homebrew/opt/[email protected]/include
Lysias answered 4/7, 2023 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.