47

Trying to set up a new macbook for a colleague. Not going well.

First I install OpenSSL:

Heathers-MacBook-Pro:~ heather$ rvm pkg install openssl
Fetching openssl-1.0.1c.tar.gz to /Users/heather/.rvm/archives
######################################################################## 100.0%
Extracting openssl to /Users/heather/.rvm/src/openssl-1.0.1c
Configuring openssl in /Users/heather/.rvm/src/openssl-1.0.1c.
Compiling openssl in /Users/heather/.rvm/src/openssl-1.0.1c.
Installing openssl to /Users/heather/.rvm/usr

Please note that it's required to reinstall all rubies:

    rvm reinstall all --force

Updating openssl certificates

Then I try to install ruby with openssl...

Heathers-MacBook-Pro:website heather$ rvm install 1.9.3 --with-openssl-dir=$HOME/.rvm/usr
Fetching yaml-0.1.4.tar.gz to /Users/heather/.rvm/archives
Extracting yaml to /Users/heather/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/heather/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/heather/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/heather/.rvm/usr
Installing Ruby from source to: /Users/heather/.rvm/rubies/ruby-1.9.3-p392, this may take a while depending on your cpu(s)...
ruby-1.9.3-p392 - #downloading ruby-1.9.3-p392, this may take a while depending on your connection...
ruby-1.9.3-p392 - #extracting ruby-1.9.3-p392 to /Users/heather/.rvm/src/ruby-1.9.3-p392
ruby-1.9.3-p392 - #extracted to /Users/heather/.rvm/src/ruby-1.9.3-p392
ruby-1.9.3-p392 - #configuring
ruby-1.9.3-p392 - #compiling
ruby-1.9.3-p392 - #installing 
Removing old Rubygems files...
Installing rubygems-1.8.25 for ruby-1.9.3-p392 ...
Installation of rubygems completed successfully.
Saving wrappers to '/Users/heather/.rvm/bin'.
ruby-1.9.3-p392 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p392 - #importing default gemsets, this may take time ...
Install of ruby-1.9.3-p392 - #complete 

Heathers-MacBook-Pro:website heather$ bundle update
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your Gemfile from 'https' to 'http'. Instructions for
compiling with OpenSSL using RVM are available at rvm.io/packages/openssl.

btw, the gem file says "source https://rubygems.org"

ideas?

phil swenson
  • 8,564
  • 20
  • 74
  • 99

16 Answers16

86

OP actually saved my day! In my case:

$ rvm pkg install openssl
$ rvm remove 2.4
$ rvm install 2.4 --with-openssl-dir=$HOME/.rvm/usr
$ gem install bundler
phq
  • 976
  • 1
  • 6
  • 3
  • 1
    Turns out that on Debian you do _not_ need `libssl-dev`; you need `libssl1.0-dev`. Running your sequence of commands highlighted the difference and solved my problem and now 2.1.10 is successfully installed. Thank you. – dimitarvp Mar 13 '18 at 20:25
  • THANK YOU! Works great to get ruby 1.8.7 on ubuntu 18.04 running – Berti92 Oct 17 '18 at 15:34
  • 1
    In my case this was the only solution which worked. Was trying to install ruby 2.3.6 which broke after upgrading a homebrew package `brew upgrade pyenv`, and some other brew updates which left `brew list` showing both `openssl & openssl@1.1` That's when my problem started. – lacostenycoder Nov 25 '19 at 19:06
  • solved it for me on Fedora 36 – Dmitrii Kharlamov May 16 '22 at 15:38
  • 1
    Thanks!!!! the solution for using ubuntu 22.04 because it uses openssl@3.0 and old ruby versions does not soupoport it – Santiago Ceron May 31 '22 at 20:48
  • Thanks! That helps me, after linux upgrade (ssl libraries probably) i had no idea how to install via rvm.. searched more then hour while found your solution. You made my day! – sumskyi Jun 21 '22 at 18:58
  • Claps and Thanks a lot. After hundreds of differents things, this one works for me. Ubuntu 22.04 Ruby 2.4.5 & 2.7.3 – Montells Jun 23 '22 at 15:00
26

It's well described on ArchLinux wiki:

Ruby versions older than 2.4 require OpenSSL 1.0 but RVM will try to build them with OpenSSL 1.1.

So you can do (easiest):

$ rvm pkg install openssl
$ rvm reinstall 2.3.5 --with-openssl-dir=$HOME/.rvm/usr

You can see more solutions on ArchLinux wiki.

noraj
  • 3,964
  • 1
  • 30
  • 38
21

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)]
fmendez
  • 7,250
  • 5
  • 36
  • 35
  • 3
    One clarifying comment - running "rvm requirements run" gives you a bunch of missing homebrew formulas. run "brew install" for each. – phil swenson Mar 19 '13 at 23:38
  • 2
    fails on `rvm get head` for me with `Error running 'command gem install /Users/daniellizik/.rvm/gem-cache/rvm-1.11.3.9.gem --local --no-document'`... `ERROR: Loading command: install (LoadError) cannot load such file -- openssl` – Daniel Lizik Jan 06 '20 at 03:37
  • Besides `rvm pkg remove` being deprecated now, I used `rvm autolibs enabled` before running `rvm requirements run` and reinstalling my intended version, so all is working fine now. – Adail Retamal Jan 31 '23 at 22:01
21

Installing Ruby 2.2 on macOS Mojave (10.14.2) with Homebrew.

Install Homebrew

brew install openssl
rvm install 2.2 --with-openssl-dir=/usr/local/opt/openssl

Don't use rvm pkg it's deprecated, use rvm autolibs enabled.

guapolo
  • 2,443
  • 2
  • 20
  • 19
  • Not everyone can use brew, rvm pkg takes care about openssl issues on Linux too where Homebrew is usually not installed ant not encouraged to use. rvm pkg is OK to use, since there is no replacement. – Gabor Garami Dec 18 '22 at 21:27
17

Here's how I installed rvm and ruby 2.3 on a mac with Catalina. The version of rvm installed was 1.29.9. OpenSSL 1.0.2 (downgrade) had to be installed. Note the "ipv4" in the gpg command.

gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable

Download openssl 1.0.2 at https://www.openssl.org/source/

tar -xzf openssl-1.0.2t.tar.gz
cd openssl-1.0.2t
./Configure darwin64-x86_64-cc --prefix=/usr/local/opt/openssl@1.0
make
make test
sudo make install

rvm install 2.3.3 --with-openssl-dir=/usr/local/opt/openssl@1.0
ruby -v
ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'              
>> OpenSSL 1.0.2t  10 Sep 2019
Chris Hobbs
  • 495
  • 6
  • 5
  • I have different projects working.With above comment 2.3.3 version project is working fine.Can you please add which openssl version will be appropriate for Ruby 2.5.3 with Rails 5.2.1 in catalina? – Minal Soni Jan 12 '20 at 08:54
  • This also works for ruby < 2.4 on osx 10.14 mojave! – RunsnbunsN Jan 29 '20 at 22:27
  • Thank you for explaining so beautifully. worked for mac os Catalina. – Surendra Rathore Feb 25 '20 at 13:38
  • If for any reason you need multiple rubies and gemsets, this is by far the most clean way to work it out (with such "old" versions as < 2.4). – Pipetus Nov 06 '20 at 20:30
9

On MacOS 10.12.2 installing openssl via brew, won't work. To fix it, run:

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

And then install Ruby via rvm.

EDIT: More information about the reason behind the problem here.

Opal
  • 81,889
  • 28
  • 189
  • 210
blazejmar
  • 1,080
  • 8
  • 10
  • This is even more important for older versions of Ruby which might not work properly with newer versions of openssl e.g. 1.1. This setting is essential to making `--with-openssl-dir` option of rvm work. – mastaBlasta Nov 15 '17 at 22:05
7

For those who have issue with openssl 1.1 and Ruby 2.3 via RVM on Mac Mojave, you could try following commands. The problem is Ruby 2.3 is not compatible with openssl 1.1

rvm pkg install openssl
PKG_CONFIG_PATH=$HOME/.rvm/usr/lib/pkgconfig rvm reinstall 2.3.3 --with-openssl-dir=$HOME/.rvm/usr
zhongxiao37
  • 977
  • 8
  • 17
6

Here is what worked for me:

brew install rbenv/tap/openssl@1.0
rvm reinstall 1.9.3-p551 --with-openssl-dir='/usr/local/opt/openssl@1.0'
gem update --system

Cheers!

Hernan
  • 101
  • 1
  • 2
  • This worked for me on Catalina, rvm, ruby 2.1.9. Now my ancient testing harness works again! – Jon V May 29 '20 at 14:29
6

For older version of ruby 2.2.10 on MacOS High Sierra 10.13.6 the only thing worked for me was:

  1. switching to older OpenSSL version
brew switch openssl 1.0.2s
  1. Than reinstalling ruby using --with-openssl-dir
rvm reinstall 2.2.10 --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2s
Yurii Verbytskyi
  • 1,962
  • 3
  • 19
  • 27
  • 2
    Thank you! This helped to install old Ruby 2.3.0 on High Sierra 10.13.6. Otherwise new openssl 1.1.x was not compatible – rilian Apr 12 '20 at 15:16
  • 1
    The problem I ran into with this was that if I didn't have openssl 1.0.x installed via brew (from an ancient leftover), the kegs no longer exist, so you can't actually install openssl 1.0.x anymore via homebrew _directly_. You have to figure out how to actually _get_ openssl1.0.x installed via homebrew first. See either Chris Hobbs' or hernan's answer for that. – Jon V May 29 '20 at 14:33
  • Thanks a bunch, this is what helped me to get an old Ruby 2.2.7 project running on macOs Catalina 10.15.4 – dutchstrider Jun 04 '20 at 20:14
4

So this worked for me:

rvm pkg install openssl
rvm reinstall all --force

I also had rvm autolibs rvm_pkg for readline support.

Dorian
  • 22,759
  • 8
  • 120
  • 116
3

Anyone on Mac using homebrew can use this command which worked for me.

rvm install 2.7.7 --with-openssl-dir=$(brew --prefix openssl)/lib

Tyler
  • 512
  • 6
  • 8
  • in my case (with multiple openssl installed via brew) it was openssl@1.1: "rvm install 3.2.0 --with-openssl-dir=$(brew --prefix openssl@1.1)/lib" – nazar kuliyev Aug 30 '23 at 06:03
2

openssl version: 1.0.2k

This worked for me:

brew reinstall openssl
ruslan
  • 909
  • 6
  • 7
2

rvm pkg install openssl $ rvm reinstall 3.1.4 --with-openssl-dir=$HOME/.rvm/usr

This saved my day !

1

For rvm on MacOS

First, check and see if you have openssl installed. You should see something like this:

$ brew --prefix openssl
/usr/local/opt/openssl@1.1

If openssl is not installed, do so.

$ brew install openssl
$ brew unlink openssl
$ brew link --force openssl

If you have more than one openssl installed, consider removing all but one to make your life easier.

$ brew cleanup openssl
$ brew list --versions openssl
$ brew uninstall <unwanted-openssl-version-here>

Now reinstall the ruby version, specifying the desired openssl path.

$ rvm reinstall <your-version-here> --with-openssl-dir=`brew --prefix openssl`

Finally, verify that your ruby was compiled with the same openssl it was linked to. If you see the same version twice, you should be all set.

$ ruby -ropenssl -e'puts OpenSSL::OPENSSL_VERSION, OpenSSL::OPENSSL_LIBRARY_VERSION'
OpenSSL 1.1.1d  10 Sep 2019
OpenSSL 1.1.1d  10 Sep 2019

If later you install other versions of ruby, you will need to pass the same --with-openssl-dir argument. Alternatively, I believe you can set the following variables in your bash profile.

export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(brew --prefix openssl)/lib/pkgconfig"
export LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix openssl)/lib"

If the above doesn't work, remove the lines from your bash profile and just use the --with-openssl-dir argument as above.

Ref: https://github.com/rvm/rvm/issues/4562 Ref: https://bugs.ruby-lang.org/issues/12630

Ben Amos
  • 1,750
  • 15
  • 18
1

For anyone using macports I found the following got things working:

$ sudo port install openssl11
$ PKG_CONFIG_PATH="/opt/local/libexec/openssl11/lib/pkgconfig" rvm reinstall 2.7.5 --with-openssl-dir='/opt/local/libexec/openssl11'
Ben Trewern
  • 1,583
  • 1
  • 10
  • 13
0

For windows (using Ubuntu WSL), I need to use the different path where openssl is found.

$ rvm pkg install openssl
$ rvm remove 2.4
$ rvm install 2.4 --with-openssl-dir=/usr/local/rvm/usr
$ gem install bundler