简体   繁体   English

安装 Ruby on Rails 时出错:“无法构建 gem 本机扩展”

[英]Error when installing Ruby on Rails: “Failed to build gem native extension”

I'm running Crunchbang 11 (Debian-based).我正在运行 Crunchbang 11(基于 Debian)。

I'm trying to install Ruby on Rails, like this:我正在尝试安装 Ruby on Rails,如下所示:

gem install rails --version 4.0.0

I get the error "Failed to build gem native extension".我收到错误“无法构建 gem 本机扩展”。

My ruby is version 2.0.0p247 , my RubyGems is 2.0.0 .我的 ruby​​ 是2.0.0p247版本,我的 RubyGems 是2.0.0

What's the issue here?这里有什么问题?


This is the full error output:这是完整的错误输出:

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

    /home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
creating Makefile

make
compiling atomic_reference.c
linking shared-object atomic_reference.so

make install
/usr/bin/install -c -m 0755 atomic_reference.so /home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/gems/atomic-1.1.10/lib/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux
/usr/bin/install: cannot create regular file `/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/gems/atomic-1.1.10/lib/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux': No such file or directory
make: *** [install-so] Error 1


Gem files will remain installed in /home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/gems/atomic-1.1.10 for inspection.
Results logged to /home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/gems/atomic-1.1.10/ext/gem_make.out

My env :我的env

ORBIT_SOCKETDIR=/tmp/orbit-erlkoenig
SSH_AGENT_PID=2695
rvm_bin_path=/home/erlkoenig/.rvm/bin
GEM_HOME=/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247
SHELL=/bin/bash
TERM=xterm-256color
XDG_SESSION_COOKIE=9e0343c07c890bd2d60ee6a750f36c6c-1373892339.852749-193038580
IRBRC=/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/.irbrc
WINDOWID=39845892
GNOME_KEYRING_CONTROL=/home/erlkoenig/.cache/keyring-g6PRS5
MY_RUBY_HOME=/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247
USER=erlkoenig
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
rvm_path=/home/erlkoenig/.rvm
SSH_AUTH_SOCK=/tmp/ssh-XVmUxMD7LHwi/agent.2651
rvm_prefix=/home/erlkoenig
PATH=/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/bin:/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247@global/bin:/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/bin:/home/erlkoenig/.rvm/bin:/home/erlkoenig/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/erlkoenig/.rvm/bin:/home/erlkoenig/.scripts:/home/erlkoenig/.scripts/netlogo-5.0.3:/opt/node/bin
MAIL=/var/mail/erlkoenig
PWD=/home/erlkoenig
EDITOR=vim
GNOME_KEYRING_PID=2575
LANG=en_US.UTF-8
rvm_env_string=ruby-2.0.0-p247
rvm_version=1.21.9 (stable)
SHLVL=1
HOME=/home/erlkoenig
rvm_ruby_string=ruby-2.0.0-p247
LOGNAME=erlkoenig
GEM_PATH=/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247:/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247@global
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-9eOdnYZelY,guid=a5db4ca68e107a48a04c8b8e51e3eef4
DISPLAY=:0.0
RUBY_VERSION=ruby-2.0.0-p247
XAUTHORITY=/home/erlkoenig/.Xauthority
COLORTERM=gnome-terminal
_=/usr/bin/env

Rails 4.0 需要 RubyGem 2.0.3 版,只需使用以下命令更新您的系统

gem update --system 2.0.3

Run the following command:运行以下命令:

sudo apt-get install ruby-dev zlib1g-dev liblzma-dev

Then,然后,

sudo gem install rails

Just a follow up ... on different solution...只是跟进......关于不同的解决方案......

it may be that you are on a mac and rails cannot find the right compiler for c headers.可能是您使用的是 mac,而 rails 找不到适合 c 头文件的编译器。

just install xcode from apps store / homebrew or go to terminal ...只需从应用商店/自制软件安装 xcode 或转到终端...

$ xcode-select --install $ xcode-select --install

complete the installation and agree on the licensing etc, then ...完成安装并同意许可等,然后...

$ sudo gem install rails $ sudo gem 安装导轨

在windows7上使用命令“gem install rails -v 5.1.2”安装rails时遇到同样的问题,在安装“MSYS2和MINGW开发工具链”后解决(命令ridk install然后选项3)。花了一段时间才完成安装然后我安装了导轨没有任何问题

Try尝试

sudo gem install rails --version 2.0

to install libraries.安装库。

For anyone got the error:"Failed to build gem native extension”, while running sudo gem install rails , and it said somethings about "nokogiri".对于任何人在运行sudo gem install rails遇到错误:“无法构建 gem 本机扩展”,它说一些关于“nokogiri”的内容。

It is possible because you are using the same ruby version as system is using (for mac user).这是可能的,因为您使用的 ruby​​ 版本与系统使用的相同(对于 mac 用户)。 The solution would be install RVM, use RVM to install another ruby version.解决方案是安装 RVM,使用 RVM 安装另一个 ruby​​ 版本。

So now you have 2 Ruby versions on your machine, RVM will automatically switch to the newly installed version.所以现在你的机器上有 2 个 Ruby 版本,RVM 会自动切换到新安装的版本。 now, you can run gem install rails without error and without sudo as well.现在,您可以无错误地运行gem install rails并且没有sudo

i'm running elementary os 5 and what i do is.我正在运行基本操作系统 5,我所做的是。

sudo gem update --system

and then try again.然后再试一次。

sudo gem install rails

On Fedora 30, I ran into this problem "Failed to build gem native extension".在 Fedora 30 上,我遇到了这个问题“无法构建 gem 本机扩展”。 The log error was "gcc: fatal error: cannot read spec file '/usr/lib/rpm/redhat/redhat-hardened-cc1': No such file or directory".日志错误是“gcc:致命错误:无法读取规范文件‘/usr/lib/rpm/redhat/redhat-hardened-cc1’:没有这样的文件或目录”。 The solution was found here .解决方案在这里找到。

If you installed all the above, but the extensions would still not compile, you are probably running a Fedora image that misses redhat-rpm-config package. In that case gcc compiler would complain about one of the following:

gcc: error: conftest.c: No such file or directory
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory
To solve this, simply run sudo dnf install redhat-rpm-config.

对我来说这有帮助:

sudo apt-get install ruby-dev

我在安装 rails 时遇到了同样的错误,但我通过运行以下命令解决了它: gem install rails而不添加sudo

I found this article for installation and I think it might solve your problem. 我找到了此文章进行安装,并且认为可以解决您的问题。 Click Here 点击这里

I could solve this way我可以这样解决

rvm use ruby --install --default

and then try again.然后再试一次。

gem install rails --no-document

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Rails上安装ruby时出错,无法构建gem本机扩展 - Error while installing ruby on rails,Failed to build gem native extension 错误:安装Rails时无法构建gem本机扩展 - ERROR: Failed to build gem native extension when installing rails 安装Ruby-无法构建gem本机扩展 - Installing Ruby - Failed to build gem native extension 安装rails时出错错误:无法构建gem本机扩展 - Error installing rails ERROR: Failed to build gem native extension Rails:安装 rmagick 时出错 - 错误:无法构建 gem 本机扩展 - Rails: Error installing rmagick - ERROR: Failed to build gem native extension Ruby on Rails-安装bdb时出错。 无法构建gem本机扩展 - Ruby on Rails - Error installing bdb. Failed to build gem native extension 在Ubuntu 16.04上安装Rails时出错,无法构建gem本机扩展 - error installing rails on ubuntu 16.04 failed to build gem native extension 安装 fcgi 时出现 Rails 错误:无法构建 gem 原生扩展 - Rails error while installing fcgi: Failed to build gem native extension 安装 rails 时出错,无法构建 gem 本机扩展 - Error installing rails, failed to build gem native extension "<i>&quot;ERROR: Failed to build gem native extension.&quot;<\/i> “错误:无法构建 gem 原生扩展。”<\/b> <i>while installing Rails<\/i>在安装 Rails 时<\/b>" - "ERROR: Failed to build gem native extension." while installing Rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM