rubyinstaller2: Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'

This project is for Ruby version 2.4 and newer. For Ruby versions < 2.4 please file an issue here.

What problems are you experiencing?

I keep getting this error message on the console even though I have the event machine gem installed and the require em/pure_ruby

Steps to reproduce

What’s the output from ridk version?

Unable to load the EventMachine C extension; To use the pure-ruby reactor, require ‘em/pure_ruby’ C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- 2.4/rubyeventmachine (LoadError) from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in require’ from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/eventmachine-1.2.5-x64-mingw32/lib/rubyeventmachine.rb:2:in <top (required)>' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in require’ from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in rescue in require' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in require’ from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/eventmachine-1.2.5-x64-mingw32/lib/eventmachine.rb:8:in <top (required)>' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in require’ from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in rescue in require' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in require’ from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/faye-websocket-0.10.7/lib/faye/websocket.rb:10:in <top (required)>' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in require’ from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:133:in rescue in require' from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:39:in require’ from C:/Ruby24-x64/flutterbot/play.rb:3:in `<main>’

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (3 by maintainers)

Commits related to this issue

Most upvoted comments

To solve the problem specified in the topic you need to run these commands:

gem uninstall eventmachine
gem install eventmachine --platform ruby

gem uninstall eventmachine gem install eventmachine --platform ruby

Although eventmachine is provided as x64-mingw platform gem, it doesn’t support ruby-2.4 or 2.5 right now. So would recommend you to do the following:

  1. Open an issue at eventmachine to update their dependency to rake-compiler-dock-0.6 and to add ruby-2.4 and 2.5 binary support this way and ask them for a new x64-mingw release.
  2. Ask the people at eventmachine, how ‘em/pure_ruby’ is supposed to work.
  3. Use gem install eventmachine --platform ruby in the meantime.

If you are using windows

Go to this folder C:\Ruby24-x64\lib\ruby\gems\{version of ruby}\gems\eventmachine-1.2.5-x64-mingw32\lib

open this file eventmachine.rb

write this require 'em/pure_ruby' in the first line of code in the file this will make it work with no issues.

To solve the problem specified in the topic you need to run these commands:

gem uninstall eventmachine
gem install eventmachine --platform ruby

Para os BRs: “Resolveu o meu problema”

@Neha5248

For Ruby 2.5 and later, try:

gem uninstall eventmachine
ridk exec pacman -Sy openssl
gem install eventmachine --platform=ruby

ridk exec pacman -Sy openssl updates MSYS2 and installs the MSYS2 openssl package. This may take a little while…

gem install eventmachine --platform=ruby installs EventMachine but forces compiling the gem

EventMachine’s current x64-mingw32 gem is not compatible with Ruby 2.6 and later, and it was accidentally built without that information in the gemspec.

Ruby 2.5 and later use OpenSSL 1.1.1. Ruby 2.4 uses OpenSSL 1.0.2, which requires a different set of commands.

I have to check whether EventMachine is defined before require em/pure_ruby to prevent getting warnings.

require 'em/pure_ruby' if not defined?(EventMachine)

This problem always occurs … No convincing answer yet

I had that error when I run bundle exec jekyll serve --livereload --trace on Jekyll.4.2.1-Ruby.3.0.3p137(mingw)-Windows. I ran gem install eventmachine --platform=ruby and it compiled at C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\eventmachine-1.2.7 but when you run bundle install it creates also C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\eventmachine-1.2.7-x64-mingw32 🤔. The command bundle info eventmachine gives me C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/eventmachine-1.2.7-x64-mingw32 and that’s confimed in the Gemfile.lock with the line eventmachine (1.2.7-x64-mingw32). So I changed that line for eventmachine (1.2.7) and then the output of bundle info eventmachine gives me C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/eventmachine-1.2.7 and finally the command bundle exec jekyll serve --livereload --trace worked ✔️

What worked for me on Apple Silicon M1 and Rails 6.1

  • Full uninstall of eventmachine: gem uninstall -aIx eventmachine followed by a rm -rf vendor/cache
  • Add eventmachine in the project Gemfile and forcing it to be from the master branch latest like this gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git', :branch => 'master'
  • Run bundle install

For those running into this problem with Jekyll’s live-reload (bundle exec jekyll serve --livereload), I tried combining several of the above solutions:

  1. Completely uninstall Ruby and MSYS2
  2. Install Ruby and MSYS2 with Ruby Installer Ruby+Devkit 2.7.2-1 (x64)
  3. gem uninstall eventmachine and choose all to uninstall
  4. ridk exec pacman -Sy openssl (run in Command Prompt, not Git Bash or some other shell)
  5. gem install eventmachine --platform ruby
  6. Open C:\Ruby27-x64\lib\ruby\gems\2.7.0\gems\eventmachine-1.2.7-x64-mingw32\lib\eventmachine.rb
  7. Insert require 'em/pure_ruby' if not defined?(EventMachine) at the top of the file

This ALMOST works, but it still crashes after a few reloads:

trace
#<Thread:0x0000000007c892c0 C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/live_reload_reactor.rb:41 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        7: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/live_reload_reactor.rb:44:in `block in start'
        6: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/eventmachine.rb:197:in `run'
        5: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:144:in `run_machine' 
        4: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:547:in `run'
        3: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:547:in `loop'        
        2: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:553:in `block in run'        1: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:595:in `crank_selectables'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/eventmachine-1.2.7-x64-mingw32/lib/em/pure_ruby.rb:595:in `select': Bad file descriptor 
(Errno::EBADF)

Really wish this issue was fixed… upstream or wherever the problem lies.


EDIT: This solution actually seems to work for me. None of the above steps needed, just one line added to Gem file. It still seems to throw the same errors, but it doesn’t prevent the site from being refreshed.

I am having this problem when using bundle exec jekyll s. Where would I apply your patch then?

gem uninstall eventmachine gem install eventmachine --platform ruby

this works on my end.

@MSP-Greg

Thank a lot it’s working fine now 😃