无法安装 Ruby 包:无法构建 gem 原生扩展

无法安装 Ruby 包:无法构建 gem 原生扩展

去年我按照博客的说明在 32 位 12.04 上安装了 ruby​​ 2.1.0 并打包了 pdfbeadshttps://railssavvy.wordpress.com/2012/06/02/install_ruby_and_rails/,并且成功了。现在看来,我已经在64位14.04上安装了ruby 2.2.0,但是在安装pdfbeads时遇到了问题。

  1. 安装 rvm 和 ruby​​:

    我听说 Ubuntu 存储库中的 ruby​​ 不起作用(但我不知道这是否仍然适用),所以我关注了 https://railssavvy.wordpress.com/2012/06/02/install_ruby_and_rails/ 安装 rvm 和 ruby​​。我不确定我是否做了正确的事:

    gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
    
    curl -L get.rvm.io | bash -s stable
    

    我本来是先跑的,但是它要求我先curl -L get.rvm.io | bash -s stable运行该命令。gpg

    然后我在 ~/.bashrc 中添加一行:

    PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
    

    在 ~/.bash_profile 中添加以下几行:

    [[ -s "$HOME/.profile" ]] && source "$HOME/.profile"
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
    

    然后我跑了:

    source ~/.rvm/scripts/rvm
    rvm requirements
    rvm autolibs disable
    
    
    $ rvm install 2.2.0
    Already installed ruby-2.2.0.
    To reinstall use:
    
        rvm reinstall ruby-2.2.0
    

    它告诉我我已经安装了 ruby​​,然后我检查了前面命令的输出,发现似乎curl -L get.rvm.io | bash -s stable已经安装了 ruby​​。然后我运行:

    rvm --default use 2.2.0
    

    我是否正确安装了 rvm 和 ruby​​?或者有更好的方法吗?

  2. 现在我想安装包pdfbeads

    $  gem install  pdfbeads
    Building native extensions.  This could take a while...
    ERROR:  Error installing pdfbeads:
        ERROR: Failed to build gem native extension.
    
        /home/t/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150322-21902-q15297.rb extconf.rb
    checking for Ruby version >= 1.8.5... yes
    checking for gcc... yes
    checking for Magick-config... no
    checking for pkg-config... yes
    checking for ImageMagick version >= 6.4.9... yes
    Package MagickCore was not found in the pkg-config search path.
    Perhaps you should add the directory containing `MagickCore.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'MagickCore' found
    Package MagickCore was not found in the pkg-config search path.
    Perhaps you should add the directory containing `MagickCore.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'MagickCore' found
    Package MagickCore was not found in the pkg-config search path.
    Perhaps you should add the directory containing `MagickCore.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'MagickCore' found
    Package MagickCore was not found in the pkg-config search path.
    Perhaps you should add the directory containing `MagickCore.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'MagickCore' found
    checking for stdint.h... yes
    checking for sys/types.h... yes
    checking for wand/MagickWand.h... no
    
    Can't install RMagick 2.13.4. Can't find MagickWand.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
        --without-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=/home/t/.rvm/rubies/ruby-2.2.0/bin/$(RUBY_BASE_NAME)
    
    extconf failed, exit code 1
    
    Gem files will remain installed in /home/t/.rvm/gems/ruby-2.2.0/gems/rmagick-2.13.4 for inspection.
    Results logged to /home/t/.rvm/gems/ruby-2.2.0/extensions/x86_64-linux/2.2.0/rmagick-2.13.4/gem_make.out
    t@ocean:/h/t/./archives$ man gem
    No manual entry for gem
    See 'man 7 undocumented' for help when manual pages are not available.
    

    我点击此链接https://askubuntu.com/a/528798/1471建议运行

    rvm install 2.2.0-dev
    

    之后看来我仍然有同样的错误:

    $  gem install  pdfbeads
    Building native extensions.  This could take a while...
    ERROR:  Error installing pdfbeads:
        ERROR: Failed to build gem native extension.
    
        /home/t/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150322-24037-mauac1.rb extconf.rb
    checking for Ruby version >= 1.8.5... yes
    checking for gcc... yes
    checking for Magick-config... no
    checking for pkg-config... yes
    checking for ImageMagick version >= 6.4.9... yes
    Package MagickCore was not found in the pkg-config search path.
    Perhaps you should add the directory containing `MagickCore.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'MagickCore' found
    Package MagickCore was not found in the pkg-config search path.
    Perhaps you should add the directory containing `MagickCore.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'MagickCore' found
    Package MagickCore was not found in the pkg-config search path.
    Perhaps you should add the directory containing `MagickCore.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'MagickCore' found
    Package MagickCore was not found in the pkg-config search path.
    Perhaps you should add the directory containing `MagickCore.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'MagickCore' found
    checking for stdint.h... yes
    checking for sys/types.h... yes
    checking for wand/MagickWand.h... no
    
    Can't install RMagick 2.13.4. Can't find MagickWand.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
        --without-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=/home/t/.rvm/rubies/ruby-2.2.0/bin/$(RUBY_BASE_NAME)
    
    extconf failed, exit code 1
    
    Gem files will remain installed in /home/t/.rvm/gems/ruby-2.2.0/gems/rmagick-2.13.4 for inspection.
    Results logged to /home/t/.rvm/gems/ruby-2.2.0/extensions/x86_64-linux/2.2.0/rmagick-2.13.4/gem_make.out
    

    我想知道如何安装该pdfbeads包吗?

谢谢!

答案1

要检查您的 ruby​​ 版本是否设置正确,您可以使用以下命令。

$ which ruby
  /path/to/ruby
$ ruby --version
  ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin13.0]

就你的情况而言,它看起来ruby设置得很好。Rvm 只是一个帮助你管理 ruby​​ 的工具。如果你不喜欢它,你会知道的。

有一些线索可以解释为什么 gem 安装失败。特别是,

checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no                   <------   There's your problem
checking for pkg-config... yes
checking for ImageMagick version >= 6.4.9... yes

您缺少成功构建 gem 所需的库。 解决方案表明它在存储库中可用。因此,您应该能够使用以下命令安装它:

sudo apt-get install libmagickwand-dev

一旦完成后,你就可以安装该 gem。

gem install  pdfbeads

注意:我还没有测试过这个解决方案,更谨慎的读者可能会注意到我在这里甚至不再使用 ubuntu。如果这不能帮你解决问题,请留言。

答案2

试试这个。它对我有用:

sudo apt-get install ruby-dev
sudo gem install pdfbeads

参考:https://stackoverflow.com/a/26161563/2433023

答案3

我最近在使用 RVM 时也遇到了这个问题。

我尝试安装 Compass,但在最近全新安装的 Ubuntu 的本机二进制文件上安装失败。

解决方案是使用 --disable-binary 的附加标志重新安装 Ruby 版本 (2.3.0),这意味着您不会安装 RVM 附带的预编译二进制文件。这意味着您的本机二进制文件在您的机器上编译。这将需要一些时间才能完成。

因此,如果您遇到此问题,请尝试:

rvm reinstall --disable-binary 2.2.0

确保将 ruby​​ 版本更新到你遇到问题的任何版本

答案4

对于 WSL(适用于 Linux 的 Windows 子系统),您需要安装build-essential包:

sudo apt install build-essential

相关内容