【问题标题】:Multiple errors while trying install ruby on rails through an ubuntu WSL terminal尝试通过 ubuntu WSL 终端在 Rails 上安装 ruby​​ 时出现多个错误
【发布时间】:2020-05-09 09:32:18
【问题描述】:

我目前正在通过 Windows 子系统为 linux 使用全新安装的 ubuntu 18.04.2 LTS。我安装了 ruby​​ 使用

sudo apt-get install ruby2.5-dev

我正在尝试使用安装导轨

gem install rails -v 5.2.3

这给了我一个Gem::FilePermissionError 错误,可以使用 sudo 修复,但是网上的多个来源说不要使用 sudo 来安装 gem,尽管它们似乎都在使用 MacOS。

当我忽略它们并尝试使用 sudo 安装时,我得到了这个:

    Building native extensions. This could take a while...
ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.7/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20200123-2772-1f46u2w.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)2.5
        --help
        --clean
/usr/lib/ruby/2.5.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /usr/lib/ruby/2.5.0/mkmf.rb:574:in `block in try_compile'
        from /usr/lib/ruby/2.5.0/mkmf.rb:521:in `with_werror'
        from /usr/lib/ruby/2.5.0/mkmf.rb:574: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.5.0/mkmf.rb:632:in `with_cflags'
        from extconf.rb:161:in `add_cflags'
        from extconf.rb:416:in `<main>'

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

  /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.7/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.10.7 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.7/gem_make.out

如果不是在 Windows 中使用的 exe 文件,我似乎找不到安装“开发工具”的方法,我也不太确定我真正需要什么“开发工具”。

mkmf.log 是这样说的:

    "gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.5.0 -I/usr/include/ruby-2.5.0/ruby/backward -I/usr/include/ruby-2.5.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2   -g -O2 -fdebug-prefix-map=/build/ruby2.5-B0MvC_/ruby2.5-2.5.1=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC  conftest.c  -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby-2.5  -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 */

我不知道这意味着什么。任何帮助将不胜感激。

【问题讨论】:

    标签: ruby-on-rails ruby rubygems windows-subsystem-for-linux mkmf


    【解决方案1】:

    您缺少编译器,并且可能缺少 WSL 设置中的许多其他基本库和工具。希望这将涵盖您需要的大部分内容:

    sudo apt-get install build-essential
    sudo apt-get install libxml2-dev libsqlite3-dev zlib1g-dev liblzma-dev
    

    【讨论】:

    • 难以置信。我按照所有说明 here 并在 Windows 10 WSL 上安装了 Ruby。我立即遇到了安装任何 gem 的问题,并阅读了无数关于权限的 SO 帖子,使用 brew、rvm 和 rbenv、DevKit、MSYS2 等。浪费了我 6 个小时的生命。这两条线修复了一切。谢谢卡斯帕!
    • 其实我说得太早了。又花了 4 个小时处理不特定的错误消息并阅读了无数的线程,我放弃了。放弃了 Windows WSL 并使用了 Ruby 安装程序。在 15 分钟内一切正常(实际工作)。
    猜你喜欢
    • 2018-03-23
    • 2017-01-11
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    • 2014-05-01
    相关资源
    最近更新 更多