315

Just installed El Capitan and can't install gem eventmachine 1.0.7. openssl is at 1.0.2a-1. Tried to use --with-ssl-dir but it seems ignored.

Reported it to their github repo as well.

Any suggestions are really appreciated. Thanks.

$ ls /usr/local/Cellar/openssl/1.0.2a-1/include/openssl/ssl.h
/usr/local/Cellar/openssl/1.0.2a-1/include/openssl/ssl.h

$ gem install eventmachine -v '1.0.7' -- --with-ssl-dir=/usr/local/Cellar/openssl/1.0.2a-1/include
/Users/pain/.rbenv/versions/2.1.2/bin/ruby -r ./siteconf20150612-56154-1hsjz2n.rb extconf.rb --with-ssl-dir=/usr/local/Cellar/openssl/1.0.2a-1/include
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_thread_fd_select()... yes
checking for rb_fdset_t in ruby/intern.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... no
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue... yes
checking for clock_gettime()... no
checking for gethrtime()... no
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling binder.cpp
In file included from binder.cpp:20:
./project.h:116:10: fatal error: 'openssl/ssl.h' file not found
#include <openssl/ssl.h>
         ^
1 error generated.
make: *** [binder.o] Error 1

make failed, exit code 2

17 Answers 17

581
$ gem install eventmachine -- --with-cppflags=-I/usr/local/opt/openssl/include                                                                                                             
Building native extensions with: '--with-cppflags=-I/usr/local/opt/openssl/include'
This could take a while...
Successfully installed eventmachine-1.0.8
1 gem installed

You can also set up bundler like this but I think that is superficial

bundle config build.eventmachine --with-cppflags=-I/usr/local/opt/openssl/include
11
  • 7
    For me, I had to install openssl first before this worked. e.g. brew install openssl.
    – Ryan Walls
    Oct 26, 2015 at 17:52
  • 1
    If you have your gems set to a specific directory in your repo, i.e. vendor/bundle then you will want to run the bundle config build.GEMNAME--with-cppflags=-I/usr/local/opt/openssl/include. I had to run the same thing with the gem puma so I imagine this is happening for other gems as well.
    – Colto
    Oct 28, 2015 at 16:11
  • 4
    see answer with: 'bundle config build.eventmachine --with-cppflags=-I$(brew --prefix openssl)/include' from lloeki. That worked for me. Not this one. Nov 5, 2015 at 1:29
  • 2
    This worked for me gem install eventmachine -v 1.0.8 -- --with-cppflags=-I/usr/local/opt/openssl/include on OSX El Capitan 10.11.5 Jul 27, 2016 at 10:15
  • 6
    for me after install brew install openssl I have to do brew link openssl --force
    – Sr. Oshiro
    Sep 1, 2016 at 14:18
265

When using bundler and homebrew:

$ bundle config build.eventmachine --with-cppflags=-I$(brew --prefix openssl)/include
$ bundle install
4
  • 4
    For me, I had to install openssl first before this worked. e.g. brew install openssl
    – Ryan Walls
    Oct 26, 2015 at 17:51
  • This version worked for me to install eventmachine 1.0.3 on top of ruby 2.1.2
    – dtburgess
    Nov 17, 2015 at 13:11
  • Fantastic! This is also the way to go for other gems (e.g. puma) that depend on openssl
    – morgler
    Mar 12, 2017 at 20:06
  • 1
    I think this answer is better than the approved one, because since it uses bundle install to perform the actual gem installation, it guarantees you'll install the exact version specified in your bundle. The accepted answer will install the latest version, unless you include the -v x.x.x in the gem install command manually.
    – Ernesto
    Jun 3, 2017 at 2:54
127
brew link --force openssl

Then:

gem install eventmachine

It also fixes:

  • gem install taks
  • bundle install
  • rake and rails tasks

P.S. Probably you'll need to remove and run brew install openssl again

The issue happends because Apple had removed openssl from OSX (in El Captain build)

6
  • 11
    This was indeed the fix on El Capitan.
    – jhedstrom
    Dec 1, 2015 at 18:37
  • For clarification, what is the order of brew remove/install/link
    – Abram
    Dec 4, 2015 at 18:19
  • 7
    @Abram In case of brew link --force openssl had no effect. Then do brew uninstall openssl, brew install openssl, brew link --force openssl
    – itsnikolay
    Dec 4, 2015 at 18:22
  • This is the answer on a Mac today (El Capitan, 2015-2016). EDIT: Just forcing the brew openssl. I didn't need to specify a version of EventMachine (I was installing Middleman). Dec 7, 2015 at 10:28
  • 1
    Worked for me as well. Good call. Jan 25, 2017 at 3:20
19
gem pristine eventmachine -- --with-cppflags=-I/usr/local/opt/openssl/include

pristine removes the old gem and recompiles it.

The cpp flags option allows the compiler to find the openssl headers.

If you prefer to abstract away the cpp flags argument, you can do the following:

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

You can also add the version if you like:

gem pristine eventmachine -v '1.0.4' -- --with-cppflags=-I/usr/local/opt/openssl/include
2
  • 1
    why pristine instead of install? Sep 20, 2016 at 11:41
  • 8
    gem install eventmachine -- --with-cppflags=-I/usr/local/opt/openssl/include worked for me. Jan 18, 2017 at 3:23
14

I was trying to install v 1.0.3 and this worked for me.

gem install eventmachine -v '1.0.3' -- --with-cppflags=-I/usr/local/opt/openssl/include

These discussions were very helpful: https://github.com/eventmachine/eventmachine/issues/602

This assumes the machine already has openssl installed via brew.

2
  • 2
    You need a hypen before I/usr/local/opt/openssl/include. It's one character so stackoverflow doesn't let me edit it
    – MaicolBen
    Mar 7, 2017 at 14:42
  • 1
    Fixed it @MaicolBen
    – blockloop
    May 3, 2017 at 20:42
9

This solved the problem for me:

PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig" gem install eventmachine -v "1.0.8"

Source: https://github.com/sj26/mailcatcher/issues/254

1
  • Unecessarily complicated, why not just set the var: export PKG_CONFIG_PATH=$( brew --prefix openssl )/lib/pkgconfig # now you can install any packages, add to .bashrc, or what you use Oct 11, 2017 at 15:03
8

If you're installing EventMachine as a dependency of another gem, be sure to specify the correct version when you manually install the gem:

gem install eventmachine -v 1.0.5 -- --with-cppflags=-I$(brew --prefix openssl)/include

Then you can install the gem that you were originally trying to install:

gem install mailcatcher
7

This looks like a more recent issue: https://github.com/eventmachine/eventmachine/issues/936

I solved this problem on macOS 12.3.1 with the following:

M1 Max:

gem install eventmachine -- --with-openssl-dir=/opt/homebrew/Cellar/[email protected]/1.1.1n/

Intel:

gem install eventmachine -- --with-openssl-dir=/usr/local/Cellar/[email protected]/1.1.1n/
2
5

One alternative is to add a bundler config entry for your whole user profile, like this:

cd ~
bundle config build.eventmachine --with-cppflags=-I$(brew --prefix openssl)/include

it'll create a .bundle/config file in your home directory, which is then used in all your projects when you run bundle install.

1
  • Lovely and still works on an M1 MBP and Ruby 3.x.
    – Joe
    Sep 12, 2021 at 20:25
5

I met the same eventmachine issue and the answers above didn't work for me, finally reinstall ruby with given openssl version works:

rvm reinstall 3.1.2 --with-openssl-dir=/usr/local/opt/openssl@3
0
4

This worked for me -

    gem install eventmachine -v '1.0.7' -- --debug --backtrace --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
    Building native extensions with: '--debug --backtrace --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib'
    This could take a while...
    Successfully installed eventmachine-1.0.7
    Parsing documentation for eventmachine-1.0.7
    Installing ri documentation for eventmachine-1.0.7
    Done installing documentation for eventmachine after 9 seconds
    1 gem installed

NOTE:- Before I was able to successfully install this gem, I had to do a few things. These might apply to you, so listing them here -

1.) got off the corporate-VPN OR you might have to turn ON proxy settings

2.) PKG_CONFIG_PATH was set to -

echo $PKG_CONFIG_PATH
/usr/local/opt/openssl/lib/pkgconfig

3.) had to add the following to $PATH in bash_profile (in my case ~/.zshrc)

export PATH="/usr/local/opt/openssl/bin:$PATH"

4.) Also note, that contrary to some answers I got in this SO post, and also this thread on github-eventmachine, I was not able to install eventmachine

gem install eventmachine -v '1.0.7' -- --debug --backtrace --with-cppflags=-I/usr/local/include --with-ldflags=-L/usr/local/lib
Fetching: eventmachine-1.0.7.gem (100%)
Building native extensions with: '--debug --backtrace --with-cppflags=-I/usr/local/include --with-ldflags=-L/usr/local/lib'
This could take a while...
ERROR:  Error installing eventmachine:
    ERROR: Failed to build gem native extension.

It seems /usr/local/opt/openssl/include is the right location and not /usr/local/include when specifying the openssl location.

2
  • 1
    This miraculously worked for me, after trying most of the other suggestions, I just had to edit the version from 1.0.7 to 1.2.7. Nov 10, 2022 at 7:22
  • 1
    This also worked for me (Ruby 3.0.0, MacOS 12.6) after unsuccessfully trying lots of other suggestions on this page. Thanks!
    – GMA
    Feb 12 at 19:59
3

Using Ventura 13.2.1 and Ruby 3.1.2, only this worked for me:

gem install eventmachine -- --with-cppflags=-I/usr/local/opt/[email protected]/include
1
  • this worked for my M1 MacBook running Ventura 13.4 (22F66)
    – Tilo
    Jun 1 at 16:44
2

This installed it for me:

gem install eventmachine -- --with-openssl-dir=/usr/local/opt/[email protected]

I got it from the eventmachine Github repo. Evidently OpenSSL tools were moved / removed from MacOS at some point.

In my case, I wanted to install something else (mailcatcher) with a dependency on eventmachine. I did this by replacing eventmachine with mailcatcher in the above command.

1

For Jekyll and Fish:

gem install jekyll -- --with-cppflags=-I(brew --prefix openssl)/include
1
  • Worked for me, except I had to change -I( to -I$( - that is, I had to add the $. So my full command was gem install jekyll -- --with-cppflags=-I$(brew --prefix openssl)/include
    – GMA
    Aug 16, 2022 at 15:21
1

As of 2022, the way to install eventmachine, assuming brew install openssl has already installed successfully, is: gem install eventmachine -- --with-cppflags=-I/opt/homebrew/opt/openssl/include

Notice that the include directory has moved.

1

The solution that worked for me was:

I had similar eventmachine issues on MAC M1 installing Jekyll. While this is inspired by Stackoverflow running brew link --force openssl did NOT solve my issues.

I could solve these Openssl issues as follows:

Run brew --prefix openssl to check the openSSL path. If OpenSSL is not installed, install it first.

Run bundle config build.eventmachine --with-openssl-dir=$(brew --prefix openssl).

Run bundle config build.eventmachine --with-cppflags=-I$(brew --prefix openssl)/include.

Run bundle

Can't install Jekyll - "fatal error: 'openssl/ssl.h' file not found"

0

With openssl@3 with Homebrew it worked by running this command:

gem install eventmachine -- --with-openssl-dir=/usr/local/opt/openssl@3/bin/openssl

NOTE the /bin/openssl at the end which made the difference for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.