无法安装 Ruby 包:无法构建 gem 本机扩展

Tim*_*Tim 4 ruby

去年,我在博客https://railssavvy.wordpress.com/2012/06/02/install_ruby_and_rails/之后在 32 位 12.04 上安装了 ruby​​ 2.1.0 并打包了 pdfbeads ,并且它起作用了。现在看来我在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
    
    Run Code Online (Sandbox Code Playgroud)

    我最初是先运行的curl -L get.rvm.io | bash -s stable,但它要求我gpg在它之前运行命令。

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

    PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
    
    Run Code Online (Sandbox Code Playgroud)

    还有几行到 ~/.bash_profile :

    [[ -s "$HOME/.profile" ]] && source "$HOME/.profile"
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
    
    Run Code Online (Sandbox Code Playgroud)

    然后我跑了:

    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
    
    Run Code Online (Sandbox Code Playgroud)

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

    rvm --default use 2.2.0
    
    Run Code Online (Sandbox Code Playgroud)

    我是否正确安装了 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.
    
    Run Code Online (Sandbox Code Playgroud)

    我按照这个链接https://askubuntu.com/a/528798/1471建议运行

    rvm install 2.2.0-dev
    
    Run Code Online (Sandbox Code Playgroud)

    之后似乎我仍然有同样的错误:

    $  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
    
    Run Code Online (Sandbox Code Playgroud)

    我想知道如何安装pdfbeads软件包?

谢谢!

Kas*_*snu 7

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

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

在你的情况下,看起来ruby设置得很好。Rvm 只是一个帮助您管理红宝石的工具。你会知道如果你不喜欢它。

有关于为什么安装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
Run Code Online (Sandbox Code Playgroud)

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

sudo apt-get install libmagickwand-dev
Run Code Online (Sandbox Code Playgroud)

完成后,您应该能够安装 gem。

gem install  pdfbeads
Run Code Online (Sandbox Code Playgroud)

注意:我还没有测试过这个解决方案,更谨慎的读者可能会注意到我在这里不再使用 ubuntu。如果这不能让您排序,请发表评论。