Ruby OpenSSL Install on Mac 10.10 Yosemite - ruby

Using brew I go though the normal install process to get rbenv and Ruby installed.
Everything goes smoothly but it is soon apparent Ruby did not install with openssl onboard.
The only thing that seems to allow rbenv to auto install openssl during the ruby install is to use this:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include /usr/include
Is this a bug in rbenv or brew that needs fixing?

There's a long thread about rbenv with openssl on Github here
The easiest way to fix it are:
1) Update to the latest version of rbenv where they fixed the CONFIGURE_OPTS options, then delete and re-build all your ruby versions.
2) Use the older version of rbenv and explictly set the CONFIGURE_OPTS to use the brew openssl:
CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install <whatever version you need>

Related

How to "recompile Ruby with OpenSSL support" using RVM?

After installing Ruby 2.3.8 via RVM I get the following error when running bundle:
You must recompile Ruby with OpenSSL support or change the sources in your Gemfile
How do I recompile Ruby with OpenSSL support?
My Solution for this:
Just run
1: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/8c9b113bc6812dc74c598c8f860017e42fba8d78/Formula/openssl.rb
2: rvm install 2.3 --with-openssl-lib=/usr/local/opt/openssl/lib --with-openssl-include=/usr/local/opt/openssl/include
(if rvm is already installed, use reinstall instead of install.)
For rvm on MacOS Mojave
In my case, the installer fails because it is using obsolete parts in the new version of openssl. This has worked for me:
Go to the "homebrew-core" folder and get back the old openssl gem(1.0.2t)
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git show 8b9d6d688f483a0f33fcfc93d433de501b9c3513:Formula/openssl.rb >> Formula/openssl\#1.0.2t.rb
Enter the file and rename the class "Openssl" to "OpensslAT102t"
brew edit Formula/openssl\#1.0.2t.rb
Install it with brew
brew install openssl#1.0.2t
Once installed, force rvm to use the installed version of ssl
# Install 2.3.8
rvm install 2.3.8 --disable-binary --with-openssl-dir=`brew --prefix openssl#1.0.2t`
# Or reinstall
rvm reinstall 2.3.8 --disable-binary --with-openssl-dir=`brew --prefix openssl#1.0.2t`

Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources

I'm attempting to install jekyll and I've encountered an error. I'm running Mac OS X 10.11.4 (El Capitan).
$gem install jekyll
ERROR : While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
$gem source -l
https://ruby.taobao.org
$which openssl
/usr/local/bin/openssl
I welcome your suggestions how to resolve this error.
Newer versions of OSX deprecated openSSL, leaving many dependencies broken. You need to reinstall ruby, but specify exactly where your openSSL libraries are. If you're using rvm then that looks like:
rvm reinstall 2.3.0 --with-openssl-dir=/usr/local/opt/openssl
If you're using homebrew, then a quick shortcut to where your libraries are is:
brew install openssl
rvm reinstall 2.3.0 --with-openssl-dir=`brew --prefix openssl`
Method 1 (Install OpenSSL)
Type all these commands in your Terminal (OSX) just to be extra sure you've done everything:
rvm get stable
brew update
brew doctor
brew install openssl
rvm install ruby-2.4 (or whatever version)
rvm use ruby-2.4 (or whatever version)
rvm gemset create jekyll
gem install jekyll
Finally, you need OpenSSL installed before you compile Ruby before you install Jekyll (or other gems)!
Method 2 (Reinstalling Ruby)
Newer versions of OSX deprecated openSSL.
You need to reinstall Ruby!
RVM with OpenSSL
rvm reinstall 2.3.0 --with-openssl-dir=/usr/local/opt/openssl
With the latest RVM version
rvm get stable
rvm reinstall ruby-2.3.0
homebrew and OpenSSL
brew install openssl
rvm reinstall 2.3.0 --with-openssl-dir=`brew --prefix openssl`
You just need to set this env variables so your compiler has the correct path for openssl libs (if using Homebrew on macOS, try brew info openssl to see this info):
$ export LDFLAGS=-L/usr/local/opt/openssl/lib
$ export CPPFLAGS=-I/usr/local/opt/openssl/include
# For pkg-config to find this software you may need to set:
$ export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig
Then reinstall your ruby (rvm reinstall ruby-version)
brew install openssl
brew info openssl # do the suggested options
$ export LDFLAGS=-L/usr/local/opt/openssl/lib
$ export CPPFLAGS=-I/usr/local/opt/openssl/include
# For pkg-config to find this software you may need to set:
$ export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig
rvm reinstall <version> --with-openssl-dir=`brew --prefix openssl`
For ubuntu 22.04. Ruby will not compile with openssl v3. Which is the openssl if you install it using brew.
Do this:
brew install openssl#1.1
rvm install 3.0.2 --with-openssl-dir=`brew --prefix openssl#1.1`
To solve this issue, you should install OpenSSL version 1.1, and link ruby to it while installing process.
Here the commands worked fine with me (macOS):
// install openssl#1.1
brew install openssl#1.1
// export PKG_CONFIG_PATH variable
export PKG_CONFIG_PATH=/opt/homebrew/opt/openssl#1.1/lib/pkgconfig
// reinstall your ruby version with openssl 1.1 dir
rvm reinstall 3.0.4 --with-openssl-dir=/opt/homebrew/opt/openssl#1.1
Considering the other answers related to openssl, we can see the same error yet when we try to execute as a superuser in some cases, as follows:
filipe#FILIPE:~$ sudo gem install bundler
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
Without superuser permissions, we can see a different behavior, a successful one, as follows:
filipe#FILIPE:~$ gem install bundler
Fetching: bundler-1.14.6.gem (100%)
Successfully installed bundler-1.14.6
Parsing documentation for bundler-1.14.6
Installing ri documentation for bundler-1.14.6
Done installing documentation for bundler after 4 seconds
1 gem installed

Ruby version not in ruby-build list for rbenv

I'm using Rails 4.2 and wanted to update my Ruby version as well with rbenv.
I used Homebrew to install ruby-build and no matter how many times I try to update via brew, Ruby version 2.1.3 won't show when I run rbenv install --list.
Usually, follow these steps to install a new Ruby version with rbenv:
$ brew update
$ brew upgrade ruby-build
$ brew upgrade rbenv
Check which versions are available after updating:
$ ruby-build --definitions
Install a specific version (for example 2.1.3) with:
$ rbenv install 2.1.3
Or if you are interested into improved support for UTF8 characters in the irb console:
$ RUBY_CONFIGURE_OPTS=--with-readline-dir=`brew --prefix readline` rbenv install 2.1.3
After these steps I usually set the newest version as my global default:
$ rbenv global 2.1.3
If you installed rbenv and ruby-build with homebrew and when you do echo $(rbenv root), you get /usr/local/var/rbenv instead of /Users/<username>/.rbenv, here is how to fix the issue.
When you install rbenv with homebrew, homebrew says:
To use Homebrew's directories rather than ~/.rbenv add to your profile:
export RBENV_ROOT=/usr/local/var/rbenv
Don't do that. Remove that line from your profile. Make sure you refresh your terminal after.
Then remove any signs of rbenv in the /usr/local/var directory:
sudo rm -r /usr/local/var/rbenv
Now when I do echo $(rbenv root) I get /Users/<username>/.rbenv instead of /usr/local/var/rbenv.
That fixed it for me.
The recommended installation from (https://github.com/sstephenson/ruby-build) states that you should install ruby-build as an rbenv plug-in.
I uninstalled ruby-build via Homebrew (brew uninstall ruby-build)
Navigated to ruby-build on my local machine and deleted it
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Now, when I run rbenv install --list, I see Ruby 2.1.3. A quick installation of: rbenv install 2.1.3 and I am now free to use 2.1.3 where I like. This also worked for my teammate.
Please update by brew upgrade ruby-build and then you should see 2.1.3 in rbenv install --list
You need to update ruby build. After update you can install all current suported versions.
If you using rbenv installed via git use
cd "$(rbenv root)"/plugins/ruby-build && git pull
Or via home brew
$ brew upgrade ruby-build
$ brew upgrade rbenv

How do I install Ruby without using RVM on OS X?

I have some issues with upgrading my Ruby version with RVM on OS X.
RMV uses MacPorts, causing me to run sudo port selfupdate, which gets a bunch of compiling errors, despite correct Xcode command line tools installed.
I found some installation instructions using Linux apt-get but unfortunately I don't have in it on my Mac.
I want to install Ruby without RVM. How can I do that?
In case Macports does not work for you, try Homebrew:
rvm autolibs homebrew
Please note: Although it is not required, you might want to install Homebrew before using it with autolibs. It keeps Homebrew out of RVM directories.
Using Homebrew, you can either install and manage a single version of Ruby:
brew update
brew install ruby
Or, even better, use rbenv as a flexible alternative to RVM:
brew update
brew install rbenv
brew install ruby-build
rbenv install 2.0.0-p247
rbenv rehash
rbenv then makes it easy to use a specific version of Ruby either globally or per project (which can then be added to source control).
Note that you may want to follow the advice from rbenv's "caveats" (brew info rbenv), particularly the part about adding eval "$(rbenv init -)" to your profile.

OpenSSL error installing ruby 2.0.0-p195 on Mac with rbenv

I'm trying to install Ruby 2.0.0-p195 using rbenv on a Mac (Mountain Lion) and got this error.
BUILD FAILED
Inspect or clean up the working tree at /var/folders/vt/27n8h2yj27v7rzq58075f3_m0000gn/T/ruby-build.20130618163859.1669
Results logged to /var/folders/vt/27n8h2yj27v7rzq58075f3_m0000gn/T/ruby-build.20130618163859.1669.log
Last 10 log lines:
installing default gems: /Users/me/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0 (build_info, cache, doc, gems, specifications)
bigdecimal 1.2.0
io-console 0.4.2
json 1.7.7
minitest 4.3.2
psych 2.0.0
rake 0.9.6
rdoc 4.0.0
test-unit 2.0.0.0
The Ruby openssl extension was not compiled. Missing the OpenSSL lib?
When I ran brew install openssl it said
Warning: openssl-1.0.1e already installed
Following a solution on this thread https://github.com/sstephenson/ruby-build/issues/305 I tried to install latest stable this way and got the same error
env CFLAGS='-g -O2' RUBY_CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline`" rbenv install 2.0.0-p195
Any ideas?
Try adding OpenSSL to the config options using the --with-openssl-dir option:
$ CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 2.0.0-p195
If you're using Homebrew, you'll need to install OpenSSL before running the above by running:
$ brew install openssl
UPDATE (see #JarkkoLaine 's comment below):
Just for the record, you should not need to use the config opts
anymore with ruby-build and homebrew. However, I had to reinstall
openssl with homebrew to make it work: brew uninstall openssl; brew
upgrade; brew install openssl; rbenv install 2.0.0-p247. See this for
more info.
I fixed this by executing:
brew link openssl --force
Mac OSX 10.9.4
Upgrading to the latest version of ruby-build fixed the problem for me:
Like the OP, I got
BUILD FAILED
Inspect or clean up the working tree at /Users/me/.rbenv/sources/2.0.0-p247
Results logged to /var/folders/3x/y_8y8vr53ws_kxj97km79q5h0000gn/T/ruby-build.20130704172404.3106.log
Last 10 log lines:
installing default gems: /Users/me/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0 (build_info, cache, doc, gems, specifications)
bigdecimal 1.2.0
io-console 0.4.2
json 1.7.7
minitest 4.3.2
psych 2.0.0
rake 0.9.6
rdoc 4.0.0
test-unit 2.0.0.0
The Ruby openssl extension was not compiled. Missing the OpenSSL lib?
but installing the latest version of ruby-build, via
# Don't forget brew doctor and brew update if required
brew upgrade ruby-build
fixed it.
Ruby-build had some changes between when the OP asked and now, which would explain why it worked for me, but not for the OP using the latest stable version of ruby-build.
For those who have problems installing openssl.
I had this error on my Mac 10.8.4
brew install openssl
created directory `/usr/local/Cellar/openssl/1.0.1e/include/openssl'
make: *** [install_sw] Error 13
READ THIS: https://github.com/mxcl/homebrew/wiki/troubleshooting
These open issues may also help:
https://github.com/mxcl/homebrew/pull/19429
Create a directory if it does not exist
sudo mkdir /usr/local/etc/openssl
Change the rights. Replace and with your name and group (e.g. serge:admin)
sudo chown -R <username>:<group> /usr/local/etc/openssl/
Repeat openssl installation
brew install openssl
Install curl-ca-bundle
brew install curl-ca-bundle
install ruby
CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 2.0.0-p195
Bingo
Solution using ruby-install:
After uninstalling and installing openssl a couple of times (probably unnecessary) I successfully tried this:
ruby-install ruby 2.1.3 -- --with-openssl-dir=`brew --prefix openssl`
The missing library is libssl*-dev* / openssl*-dev*, depending your distribution.
This issue came up again for me with Mac OS 10.9.5
Mac upgraded the command-line tools and that upgraded openssl, which broken rbenv.
I tried all of these solutions, but none of them worked. Everything was up-to-date, but I couldn't install any new gems or build rubies.
My solution was to:
Remove the ruby version (for me it was 2.1.1)
Brew uninstall ruby-build and rbenv
Brew Re-install rbenv and ruby-build
Hope this helps you if you encounter it too!

Resources