首页 > 解决方案 > Gem::Ext::BuildError: 错误: 无法构建 gem 原生扩展 - 找不到 msgpack-1.2.7

问题描述

系统:操作系统:Mac Catalina (10.15.3) Ruby:2.6.1p33 Bundler:2.1.4

为 Rails 应用程序运行 bundle install 会给我这个错误消息:

在任何来源中都找不到 msgpack-1.2.7。运行bundle install以安装缺少的 gem。

Could not find msgpack-1.2.7 in any of the sources
Run `bundle install` to install missing gems.
Jelenas-MBP:rails-dynamic-request-readme-austin-web-012720 galapagos$ bundle install
Fetching gem metadata from https://rubygems.org/............
Using rake 12.3.2
Using concurrent-ruby 1.1.4
Using i18n 1.6.0
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.0.7.1
Using builder 3.2.3
Using erubis 2.7.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.7
Using rails-dom-testing 2.0.3
Using crass 1.0.5
Using loofah 2.4.0
Using rails-html-sanitizer 1.0.4
Using actionview 5.0.7.1
Using rack 2.0.8
Using rack-test 0.6.3
Using actionpack 5.0.7.1
Using nio4r 2.3.1
Using websocket-extensions 0.1.3
Using websocket-driver 0.6.5
Using actioncable 5.0.7.1
Using globalid 0.4.2
Using activejob 5.0.7.1
Using mini_mime 1.0.1
Using mail 2.7.1
Using actionmailer 5.0.7.1
Using activemodel 5.0.7.1
Using arel 7.1.4
Using activerecord 5.0.7.1
Using public_suffix 3.0.3
Using addressable 2.6.0
Fetching msgpack 1.2.7
Installing msgpack 1.2.7 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/galapagos/.rvm/gems/ruby-2.6.1/gems/msgpack-1.2.7/ext/msgpack
/Users/galapagos/.rvm/rubies/ruby-2.6.1/bin/ruby -I
/Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0 -r
./siteconf20200222-12833-1ualt51.rb extconf.rb
checking for ruby/st.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/Users/galapagos/.rvm/rubies/ruby-2.6.1/bin/$(RUBY_BASE_NAME)
/Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed
to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:601:in `try_cpp'
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in
postpone'
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:331:in `open'
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:331:in `open'
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
        from /Users/galapagos/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
        from extconf.rb:3:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/galapagos/.rvm/gems/ruby-2.6.1/extensions/x86_64-darwin-19/2.6.0/msgpack-1.2.7/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/galapagos/.rvm/gems/ruby-2.6.1/gems/msgpack-1.2.7 for
inspection.
Results logged to
/Users/galapagos/.rvm/gems/ruby-2.6.1/extensions/x86_64-darwin-19/2.6.0/msgpack-1.2.7/gem_make.out

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

In Gemfile:
  bootsnap was resolved to 1.4.1, which depends on
    msgpack
Jelenas-MBP:rails-dynamic-request-readme-austin-web-012720 galapagos$ rails -v
Could not find msgpack-1.2.7 in any of the sources
Run `bundle install` to install missing gems.
Jelenas-MBP:rails-dynamic-request-readme-austin-web-012720 galapagos$ bundler -v
Bundler version 2.1.4
Jelenas-MBP:rails-dynamic-request-readme-austin-web-012720 galapagos$ rails s
Could not find msgpack-1.2.7 in any of the sources
Run `bundle install` to install missing gems.

标签: ruby-on-rails

解决方案


运行以下命令:

gem install bundler

推荐阅读