Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails bundle can't install gem ffi

Note: I gave up on this and decided to try Rails 6 and Webpacker rather than fighting this fight. Moving on to other fights.

An error occurred while installing ffi (1.13.1), and Bundler cannot continue. I know this a recurring problem and I've run into it before with nokogiri, but can't seem to find the solution this time. I have read and tried many suggestions based on searching SO and what shows up as similar questions.

Partial Gemfile:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
   repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
      "https://github.com/#{repo_name}.git"
end

ruby '2.7.0'
gem 'rails', '~> 5.2.0' 
gem 'pg' , '~> 0.18' 
gem 'puma'
gem 'bootstrap', '~> 4'

Terminal (edited slightly), starting at responding to the error:

➜ gem install ffi -v '1.13.1' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
Successfully installed ffi-1.13.1
1 gem installed

➜ bundle update
Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies..........
Using rake 13.0.1
<long list of gems installed>
Using bundler 2.1.4
Using rails 5.2.4.3
Using execjs 2.7.0
Fetching ffi 1.13.1
Installing ffi 1.13.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: <project>/vendor/bundle/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c
/Users/me/.rubies/ruby-2.7.0/bin/ruby -I ~/.rubies/ruby-2.7.0/lib/ruby/2.7.0 -r ./siteconf20200613-94985-w9dh35.rb extconf.rb
checking for ffi_prep_closure_loc() in -lffi... no
checking for ffi_prep_closure_loc() in -llibffi... no
checking for ffi_prep_closure_loc() in -llibffi-8... no
creating extconf.h
creating Makefile

current directory: <project>/vendor/bundle/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c
make "DESTDIR=" clean

current directory: <project>/vendor/bundle/ruby/2.7.0/gems/ffi-1.13.1/ext/ffi_c
make "DESTDIR="
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** ["/Users/me/Documents/Folder] Error 2

make failed, exit code 2

Gem files will remain installed in <project>/vendor/bundle/ruby/2.7.0/gems/ffi-1.13.1 for inspection.
Results logged to <project>/vendor/bundle/ruby/2.7.0/extensions/x86_64-darwin-18/2.7.0-static/ffi-1.13.1/gem_make.out

An error occurred while installing ffi (1.13.1), and Bundler cannot continue.
Make sure that `gem install ffi -v '1.13.1' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  ffi
  

Some of the things I've tried based on SO posts on this and similar problems

Removed Gemfile.lock and still bundle install failed

Tried ruby-install ruby 2.7.0 just in case. I'm using chruby and still bundle install failed

sudo xcodebuild -license and still bundle install failed

Tried commenting out source github and still bundle install failed

Tried gem install ffi and still bundle install failed

I have another app that uses similar gems but I had updated it to Rails 6, but it was at ruby-2.6.6, so tried changing to ruby-2.6.6 in terminal and Gemfile, ran bundle install and got the same kind of failure but for nokogiri.

I got trapped in this while trying to make changes on a two-year old app and then couldn't push to heroku.

I think I get that this a dependency issue, but am lost beyond that. Thanks for any suggestions.

Gemfile.lock with everything that depends on ffi removed (bootstrap) so bundle update could run without errors.

GEM
  remote: https://rubygems.org/
  specs:
    actioncable (5.2.4.3)
      actionpack (= 5.2.4.3)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
    actionmailer (5.2.4.3)
      actionpack (= 5.2.4.3)
      actionview (= 5.2.4.3)
      activejob (= 5.2.4.3)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 2.0)
    actionpack (5.2.4.3)
      actionview (= 5.2.4.3)
      activesupport (= 5.2.4.3)
      rack (~> 2.0, >= 2.0.8)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.2)
    actionview (5.2.4.3)
      activesupport (= 5.2.4.3)
      builder (~> 3.1)
      erubi (~> 1.4)
      rails-dom-testing (~> 2.0)
      rails-html-sanitizer (~> 1.0, >= 1.0.3)
    activejob (5.2.4.3)
      activesupport (= 5.2.4.3)
      globalid (>= 0.3.6)
    activemodel (5.2.4.3)
      activesupport (= 5.2.4.3)
    activerecord (5.2.4.3)
      activemodel (= 5.2.4.3)
      activesupport (= 5.2.4.3)
      arel (>= 9.0)
    activerecord-postgis-adapter (5.2.2)
      activerecord (~> 5.1)
      rgeo-activerecord (~> 6.0)
    activestorage (5.2.4.3)
      actionpack (= 5.2.4.3)
      activerecord (= 5.2.4.3)
      marcel (~> 0.3.1)
    activesupport (5.2.4.3)
      concurrent-ruby (~> 1.0, >= 1.0.2)
      i18n (>= 0.7, < 2)
      minitest (~> 5.1)
      tzinfo (~> 1.1)
    addressable (2.7.0)
      public_suffix (>= 2.0.2, < 5.0)
    ansi (1.5.0)
    arel (9.0.0)
    ast (2.4.1)
    awesome_print (1.8.0)
    aws-eventstream (1.1.0)
    aws-partitions (1.329.0)
    aws-sdk-core (3.99.2)
      aws-eventstream (~> 1, >= 1.0.2)
      aws-partitions (~> 1, >= 1.239.0)
      aws-sigv4 (~> 1.1)
      jmespath (~> 1.0)
    aws-sdk-kms (1.34.1)
      aws-sdk-core (~> 3, >= 3.99.0)
      aws-sigv4 (~> 1.1)
    aws-sdk-s3 (1.68.1)
      aws-sdk-core (~> 3, >= 3.99.0)
      aws-sdk-kms (~> 1)
      aws-sigv4 (~> 1.1)
    aws-sigv4 (1.1.4)
      aws-eventstream (~> 1.0, >= 1.0.2)
    bcrypt (3.1.13)
    better_errors (2.7.1)
      coderay (>= 1.0.0)
      erubi (>= 1.0.0)
      rack (>= 0.9.0)
    bindex (0.8.1)
    binding_of_caller (0.8.0)
      debug_inspector (>= 0.0.1)
    builder (3.2.4)
    byebug (11.1.3)
    capybara (2.18.0)
      addressable
      mini_mime (>= 0.1.3)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (>= 2.0, < 4.0)
    carrierwave (1.1.0)
      activemodel (>= 4.0.0)
      activesupport (>= 4.0.0)
      mime-types (>= 1.16)
    childprocess (3.0.0)
    choice (0.2.0)
    coderay (1.1.3)
    comfy_bootstrap_form (4.0.9)
      rails (>= 5.0.0)
    concurrent-ruby (1.1.6)
    crass (1.0.6)
    database_cleaner (1.8.5)
    debug_inspector (0.0.3)
    docile (1.3.2)
    dotenv (2.7.5)
    dotenv-rails (2.7.5)
      dotenv (= 2.7.5)
      railties (>= 3.2, < 6.1)
    erubi (1.9.0)
    execjs (2.7.0)
    font-awesome-rails (4.7.0.5)
      railties (>= 3.2, < 6.1)
    globalid (0.4.2)
      activesupport (>= 4.2.0)
    gon (6.3.2)
      actionpack (>= 3.0.20)
      i18n (>= 0.7)
      multi_json
      request_store (>= 1.0)
    guard-compat (1.2.1)
    guard-minitest (2.4.6)
      guard-compat (~> 1.2)
      minitest (>= 3.0)
    heroku_db_restore (0.0.5)
    i18n (1.8.3)
      concurrent-ruby (~> 1.0)
    jbuilder (2.10.0)
      activesupport (>= 5.0.0)
    jmespath (1.4.0)
    jquery-rails (4.4.0)
      rails-dom-testing (>= 1, < 3)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (6.0.1)
      railties (>= 3.2.16)
    leaflet-draw-rails (0.1.0)
    loofah (2.5.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.5.9)
    mail (2.7.1)
      mini_mime (>= 0.1.1)
    marcel (0.3.3)
      mimemagic (~> 0.3.2)
    method_source (1.0.0)
    mime-types (3.3.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2020.0512)
    mimemagic (0.3.5)
    mini_mime (1.0.2)
    mini_portile2 (2.4.0)
    minitest (5.14.1)
    minitest-reporters (1.1.9)
      ansi
      builder
      minitest (>= 5.0)
      ruby-progressbar
    multi_json (1.14.1)
    nio4r (2.5.2)
    nokogiri (1.10.9)
      mini_portile2 (~> 2.4.0)
    paper_trail (10.3.1)
      activerecord (>= 4.2)
      request_store (~> 1.1)
    parallel (1.19.1)
    parser (2.7.1.3)
      ast (~> 2.4.0)
    pg (0.21.0)
    pry (0.13.1)
      coderay (~> 1.1)
      method_source (~> 1.0)
    pry-byebug (3.9.0)
      byebug (~> 11.0)
      pry (~> 0.13.0)
    public_suffix (4.0.5)
    puma (4.3.5)
      nio4r (~> 2.0)
    rack (2.2.2)
    rack-test (1.1.0)
      rack (>= 1.0, < 3)
    rails (5.2.4.3)
      actioncable (= 5.2.4.3)
      actionmailer (= 5.2.4.3)
      actionpack (= 5.2.4.3)
      actionview (= 5.2.4.3)
      activejob (= 5.2.4.3)
      activemodel (= 5.2.4.3)
      activerecord (= 5.2.4.3)
      activestorage (= 5.2.4.3)
      activesupport (= 5.2.4.3)
      bundler (>= 1.3.0)
      railties (= 5.2.4.3)
      sprockets-rails (>= 2.0.0)
    rails-controller-testing (1.0.2)
      actionpack (~> 5.x, >= 5.0.1)
      actionview (~> 5.x, >= 5.0.1)
      activesupport (~> 5.x)
    rails-dom-testing (2.0.3)
      activesupport (>= 4.2.0)
      nokogiri (>= 1.6)
    rails-erd (1.6.0)
      activerecord (>= 4.2)
      activesupport (>= 4.2)
      choice (~> 0.2.0)
      ruby-graphviz (~> 1.2)
    rails-html-sanitizer (1.3.0)
      loofah (~> 2.3)
    railties (5.2.4.3)
      actionpack (= 5.2.4.3)
      activesupport (= 5.2.4.3)
      method_source
      rake (>= 0.8.7)
      thor (>= 0.19.0, < 2.0)
    rainbow (3.0.0)
    rake (13.0.1)
    regexp_parser (1.7.1)
    request_store (1.5.0)
      rack (>= 1.4)
    rexml (3.2.4)
    rgeo (2.1.1)
    rgeo-activerecord (6.2.1)
      activerecord (>= 5.0)
      rgeo (>= 1.0.0)
    rgeo-geojson (2.1.1)
      rgeo (>= 1.0.0)
    rubocop (0.85.1)
      parallel (~> 1.10)
      parser (>= 2.7.0.1)
      rainbow (>= 2.2.2, < 4.0)
      regexp_parser (>= 1.7)
      rexml
      rubocop-ast (>= 0.0.3)
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 1.4.0, < 2.0)
    rubocop-ast (0.0.3)
      parser (>= 2.7.0.1)
    ruby-graphviz (1.2.5)
      rexml
    ruby-progressbar (1.10.1)
    rubyzip (2.3.0)
    selenium-webdriver (3.142.7)
      childprocess (>= 0.5, < 4.0)
      rubyzip (>= 1.2.2)
    simplecov (0.18.5)
      docile (~> 1.1)
      simplecov-html (~> 0.11)
    simplecov-html (0.12.2)
    sprockets (4.0.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)
    sprockets-rails (3.2.1)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)
    super_awesome_print (0.2.5)
      awesome_print
    tether-rails (1.4.0)
      rails (>= 3.1)
    thor (1.0.1)
    thread_safe (0.3.6)
    tzinfo (1.2.7)
      thread_safe (~> 0.1)
    uglifier (4.2.0)
      execjs (>= 0.3.0, < 3)
    unicode-display_width (1.7.0)
    web-console (3.7.0)
      actionview (>= 5.0)
      activemodel (>= 5.0)
      bindex (>= 0.4.0)
      railties (>= 5.0)
    websocket-driver (0.7.2)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    xpath (3.2.0)
      nokogiri (~> 1.8)

PLATFORMS
  ruby

DEPENDENCIES
  activerecord-postgis-adapter
  awesome_print
  aws-sdk-s3 (~> 1)
  bcrypt (~> 3.1.11)
  better_errors
  binding_of_caller
  byebug
  capybara (~> 2.13)
  carrierwave (= 1.1.0)
  comfy_bootstrap_form (~> 4.0.0)
  database_cleaner
  dotenv-rails
  font-awesome-rails
  gon
  guard-minitest (= 2.4.6)
  heroku_db_restore
  jbuilder (~> 2.7)
  jquery-rails
  jquery-ui-rails
  leaflet-draw-rails
  minitest-reporters (= 1.1.9)
  paper_trail
  pg (~> 0.18)
  pry-byebug
  puma
  rails (~> 5.2.0)
  rails-controller-testing (= 1.0.2)
  rails-erd
  rgeo-geojson
  rubocop
  selenium-webdriver
  simplecov
  super_awesome_print
  tether-rails
  uglifier
  web-console (>= 3.5.1)

RUBY VERSION
   ruby 2.7.0p0

BUNDLED WITH
   2.1.4
like image 578
Greg Avatar asked Jun 14 '20 04:06

Greg


2 Answers

I found this answer (from https://stackoverflow.com/a/63267668/592820) helpful:

brew upgrade libffi
export LDFLAGS="-L/usr/local/opt/libffi/lib"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
bundle install
like image 77
Clinton Blackburn Avatar answered Sep 30 '22 01:09

Clinton Blackburn


Was getting this error and resolved by following steps in:

  • https://medium.com/@leoliang.climber/missing-ffi-prep-closure-error-for-ffi-1-13-1-gem-70f800a48090

gem install ffi -- --disable-system-libffi

bundle install

Edit: I had to install xcode in appstore as well. ruby version 2.6.5, rails 6.

like image 22
chubb5000 Avatar answered Sep 30 '22 03:09

chubb5000