安装 Ruby on Rails (Arch Linux) 时出错

安装 Ruby on Rails (Arch Linux) 时出错

目前,我在尝试在 Arch Linux ARM 系统上安装 Ruby on Rails 时遇到问题。但不仅仅是 Rails 无法安装,我尝试使用gem.这是一些额外的信息:

一般系统信息: [alarm@alarm ~]$ uname -a Linux alarm 3.8.11-4-ARCH #1 SMP Sat Oct 22 11:59:55 MDT 2016 armv7l GNU/Linux

宝石输出:

[alarm@alarm ~]$ gem install rails
WARNING:  You don't have /home/alarm/.gem/ruby/2.4.0/bin in your PATH,
      gem executables will not run.
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    current directory: /home/alarm/.gem/ruby/2.4.0/gems/nokogiri-1.8.0/ext/nokogiri
/usr/bin/ruby -r ./siteconf20170828-1999-1wpxia.rb extconf.rb
checking if the C compiler accepts ... *** 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=/usr/bin/$(RUBY_BASE_NAME)
    --help
    --clean
/usr/lib/ruby/2.4.0/mkmf.rb:457:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/lib/ruby/2.4.0/mkmf.rb:572:in `block in try_compile'
    from /usr/lib/ruby/2.4.0/mkmf.rb:523:in `with_werror'
    from /usr/lib/ruby/2.4.0/mkmf.rb:572:in `try_compile'
    from extconf.rb:138:in `nokogiri_try_compile'
    from extconf.rb:162:in `block in add_cflags'
    from /usr/lib/ruby/2.4.0/mkmf.rb:630:in `with_cflags'
    from extconf.rb:161:in `add_cflags'
    from extconf.rb:407:in `<main>'

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

  /home/alarm/.gem/ruby/2.4.0/extensions/armv7l-linux/2.4.0/nokogiri-1.8.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/alarm/.gem/ruby/2.4.0/gems/nokogiri-1.8.0 for inspection.
Results logged to /home/alarm/.gem/ruby/2.4.0/extensions/armv7l-linux/2.4.0/nokogiri-1.8.0/gem_make.out

mkmf.log 文件内容:

[alarm@alarm ~]$ cat /home/alarm/.gem/ruby/2.4.0/extensions/armv7l-linux/2.4.0/nokogiri-1.8.0/mkmf.log
"gcc -o conftest -I/usr/include/ruby-2.4.0/armv7l-linux-eabihf -I/usr/include/ruby-2.4.0/ruby/backward -I/usr/include/ruby-2.4.0 -I. -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64  -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -fPIC  conftest.c  -L. -L/usr/lib -L. -Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby  -lpthread -lgmp -ldl -lcrypt -lm   -lc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

答案1

查看您的错误消息以获取线索:

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 have to install development tools first.

和:

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

  /home/alarm/.gem/ruby/2.4.0/extensions/armv7l-linux/2.4.0/nokogiri-1.8.0/mkmf.log

所以听起来你缺少一些头文件(即“开发工具”),这些文件通常与 Arch Linux 上的库捆绑在一起。正如错误消息中提到的,您可以查看该文件/home/alarm/.gem/ruby/2.4.0/extensions/armv7l-linux/2.4.0/nokogiri-1.8.0/mkmf.log,它会告诉您构建过程正在寻找哪些头文件,这应该会引导您找到需要安装的库包。

答案2

我在 Arch Linux 上遇到了完全相同的问题,日志文件与上面相同。

基于 https://bbs.archlinux.org/viewtopic.php?id=114837 我做到了

pacman -S base-devel

这解决了我的问题,之后导轨安装得很好。根据该线程中的评论,似乎“pkg-config”是我缺少的包,但我不介意安装所有的 base-devel。

相关内容