Ubuntu 18.04 上“安装 Rails 时出错”,因为“extconf.rb 失败”

glo*_*esk 6 bash installation ruby-on-rails environment-variables rvm

我无法安装 Rails。

\n\n

背景:我的(全新)系统= Ubuntu 18.04,Ruby 2.6.0,安装并更新了最新的rvm和bundler。安装 Ruby 后我做的第一件事就是sudo apt install ruby-railties……sudo apt install rails我不知道为什么我不使用gem install. 在那之后,我从未成功执行过rails new,但我曾经部分执行过它,但它失败了,那就是我开始进入兔子洞的时候。

\n\n

当我输入时rails -v我得到这个:

\n\n
Traceback (most recent call last):\n    4: from /home/globewalldesk/.rvm/gems/ruby-2.6.0/bin/ruby_executable_hooks:24:in `<main>\'\n    3: from /home/globewalldesk/.rvm/gems/ruby-2.6.0/bin/ruby_executable_hooks:24:in `eval\'\n    2: from /home/globewalldesk/.rvm/gems/ruby-2.6.0/bin/rails:23:in `<main>\'\n    1: from /usr/share/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/bundler/rubygems_integration.rb:482:in `block in replace_bin_path\'\n/usr/share/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/bundler/rubygems_integration.rb:462:in `block in replace_bin_path\': can\'t find executable rails for gem railties. railties is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我尝试执行时gem install rails,我得到这个:

\n\n
Successfully installed concurrent-ruby-1.1.4\n\nHEADS UP! i18n 1.1 changed fallbacks to exclude default locale.\nBut that may break your application.\n\nPlease check your Rails app for \'config.i18n.fallbacks = true\'.\nIf you\'re using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be\n\'config.i18n.fallbacks = [I18n.default_locale]\'.\nIf not, fallbacks will be broken in your app by I18n 1.1.x.\n\nFor more info see:\nhttps://github.com/svenfuchs/i18n/releases/tag/v1.1.0\n\nSuccessfully installed i18n-1.5.2\nSuccessfully installed thread_safe-0.3.6\nSuccessfully installed tzinfo-1.2.5\nSuccessfully installed activesupport-5.2.2\nSuccessfully installed rack-2.0.6\nSuccessfully installed rack-test-1.1.0\nSuccessfully installed mini_portile2-2.4.0\nBuilding native extensions. This could take a while...\nERROR:  Error installing rails:\n    ERROR: Failed to build gem native extension.\n\n    current directory: /home/globewalldesk/.rvm/gems/ruby-2.6.0/gems/nokogiri-1.10.1/ext/nokogiri\n/usr/share/rvm/rubies/ruby-2.6.0/bin/ruby -I /usr/share/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0 -r ./siteconf20190116-22693-tbjpnz.rb extconf.rb\nchecking if the C compiler accepts ... yes\nBuilding nokogiri using packaged libraries.\n*** extconf.rb failed ***\nCould not create Makefile due to some reason, probably lack of necessary\nlibraries and/or headers.  Check the mkmf.log file for more details.  You may\nneed configuration options.\n\nProvided configuration options:\n    --with-opt-dir\n    --without-opt-dir\n    --with-opt-include\n    --without-opt-include=${opt-dir}/include\n    --with-opt-lib\n    --without-opt-lib=${opt-dir}/lib\n    --with-make-prog\n    --without-make-prog\n    --srcdir=.\n    --curdir\n    --ruby=/usr/share/rvm/rubies/ruby-2.6.0/bin/$(RUBY_BASE_NAME)\n    --help\n    --clean\n    --use-system-libraries\n/usr/share/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem\': mini_portile2 is not part of the bundle. Add it to your Gemfile. (Gem::LoadError)\n    from extconf.rb:469:in `<main>\'\n\nTo see why this extension failed to compile, please check the mkmf.log which can be found here:\n\n  /home/globewalldesk/.rvm/gems/ruby-2.6.0/extensions/x86_64-linux/2.6.0/nokogiri-1.10.1/mkmf.log\n\nextconf failed, exit code 1\n\nGem files will remain installed in /home/globewalldesk/.rvm/gems/ruby-2.6.0/gems/nokogiri-1.10.1 for inspection.\nResults logged to /home/globewalldesk/.rvm/gems/ruby-2.6.0/extensions/x86_64-linux/2.6.0/nokogiri-1.10.1/gem_make.out\n
Run Code Online (Sandbox Code Playgroud)\n\n

我在这里和其他地方查看了安装说明和许多类似的问题,并尝试了很多东西,但似乎没有任何效果。

\n\n

当我尝试时,我收到类似的错误消息gem install nokogiri

\n\n

帮助!

\n\n
\n\n

更新:这是 mkmf.log 文件:

\n\n
"gcc -o conftest -I/usr/share/rvm/rubies/ruby-2.6.0/include/ruby-2.6.0/x86_64-linux -I/usr/share/rvm/rubies/ruby-2.6.0/include/ruby-2.6.0/ruby/backward -I/usr/share/rvm/rubies/ruby-2.6.0/include/ruby-2.6.0 -I.    -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wrestrict -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable  -fPIC  conftest.c  -L. -L/usr/share/rvm/rubies/ruby-2.6.0/lib -Wl,-rpath,/usr/share/rvm/rubies/ruby-2.6.0/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/usr/share/rvm/rubies/ruby-2.6.0/lib -L/usr/share/rvm/rubies/ruby-2.6.0/lib -lruby  -lm   -lc "\nchecked program was:\n/* begin */\n1: #include "ruby.h"\n2: \n3: int main(int argc, char **argv)\n4: {\n5:   return 0;\n6: }\n/* end */\n\n"gcc -I/usr/share/rvm/rubies/ruby-2.6.0/include/ruby-2.6.0/x86_64-linux -I/usr/share/rvm/rubies/ruby-2.6.0/include/ruby-2.6.0/ruby/backward -I/usr/share/rvm/rubies/ruby-2.6.0/include/ruby-2.6.0 -I.    -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wrestrict -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable  -fPIC    -Werror -c conftest.c"\nchecked program was:\n/* begin */\n1: #include "ruby.h"\n2: \n3: int main() {return 0;}\n/* end */\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n

更新2:采纳哈维尔的建议,我查看了安装Nokogiri的文档并找到了gem install nokogiri -- --use-system-libraries有效的命令。然后我对铁轨和铁轨做了同样的事情。

\n\n

现在,当我尝试运行时收到不同的错误消息rails new

\n\n
Traceback (most recent call last):\n    2: from /home/globewalldesk/.rvm/gems/ruby-2.6.0/bin/rails:23:in `<main>\'\n    1: from /usr/share/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/bundler/rubygems_integration.rb:482:in `block in replace_bin_path\'\n/usr/share/rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/bundler/rubygems_integration.rb:462:in `block in replace_bin_path\': can\'t find executable rails for gem railties. railties is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)\nO\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n

更新3:

\n\n

我接受了哈维尔的回答。我一直在进行全新安装(尝试),所以如果我完全重新开始也没关系。我不知道最终是什么搞砸了我的系统(也许是因为我从另一个系统复制了旧的 .bashrc 文件,而没有先删除 rvm 行?),但完全卸载了所有 Ruby、Rails、其他 gems 和 rvm,然后重新安装应该可以解决问题。

\n\n

更新最后:

\n\n

完全卸载 Ruby、Rails,尤其是 RVM 花了相当多的时间。我没有\xe2\x80\x99意识到Bash配置文件脚本有多么重要,或者需要从其中彻底删除有关RVM的行,或者RVM设置的某些环境变量的状态有多么重要。我认为安装 Rails 时遇到问题的主要原因是我从旧的 bash 配置文件中复制了 RVM 设置。我应该把它们去掉。

\n\n

现在一切都按预期进行。

\n

Jav*_*izo 4

这是安装 nokogiri 的文档https://nokogiri.org/tutorials/installing_nokogiri.html,有一个关于rvm的注释:

RVM 用户请注意:您可能需要 libgmp,请考虑运行 sudo apt-get install libgmp-dev。

使用 rvm 删除 ruby​​ https://rvm.io/rubies/removing

rvm remove 2.6.0
Run Code Online (Sandbox Code Playgroud)

安装

红宝石

rvm install 2.6.0
Run Code Online (Sandbox Code Playgroud)

导轨

gem install rails
Run Code Online (Sandbox Code Playgroud)

对于现有项目

bundle install
Run Code Online (Sandbox Code Playgroud)