错误:尝试下载Rubocop时无法构建gem本机扩展


13

当我尝试“ sudo gem install rubocop”时,我得到...

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

    current directory: /var/lib/gems/2.3.0/gems/rainbow-2.2.1/ext
/usr/bin/ruby2.3 mkrf_conf.rb

current directory: /var/lib/gems/2.3.0/gems/rainbow-2.2.1/ext
/usr/bin/ruby2.3 -rubygems /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake RUBYARCHDIR=/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.1 RUBYLIBDIR=/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.1
/usr/bin/ruby2.3: No such file or directory -- /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake (LoadError)

rake failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/rainbow-2.2.1 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/rainbow-2.2.1/gem_make.out

因此,我尝试了多种解决方案,特别是来自/programming/22544754/failed-to-build-gem-native-extension-installing-compass的解决方案(不同的gem,相同的错误)

我尝试用“ rvm reinstall --disable-binary 2.2.0”重新安装RVM,这花了一段时间,但没有解决

接下来我尝试$“ sudo apt-get install ruby​​-dev”这会产生

Reading package lists... Done
Building dependency tree       
Reading state information... Done
ruby-dev is already the newest version (1:2.3.0+1).
The following packages were automatically installed and are no longer required:
  dkms linux-headers-4.4.0-53 linux-headers-4.4.0-53-generic
  linux-image-4.4.0-53-generic linux-image-extra-4.4.0-53-generic
  python-appindicator python-gconf python-gi python-glade2
  python-gobject python-pexpect python-ptyprocess python-xdg
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 40 not upgraded.

我还尝试了“ gem update --system”,我得到了...

Latest version currently installed. Aborting.

任何建议都将不胜感激,因为我是一个菜鸟,而且我陷于困境。


如错误所示,您已rake安装吗?
muru

是的 我有最新版本。
user642832

Answers:


27

sudo gem install rake然后再做sudo gem install rubocop一次,它应该可以工作。

安装正确版本的rake似乎并不重要。rake --version据我报告,10.5.0但我仍然收到与您相同的错误消息。查看错误消息,它正在查找rake特定路径,而不仅仅是my PATH:上的任何地方/usr/bin/ruby2.3: No such file or directory -- /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake (LoadError)which rake报告/usr/local/bin/rake,不是/usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake。实际上,如错误消息所示,处没有文件/usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake。这可能与rakeapt-get installed而不是gem installed有关。sudo gem install rake创建该文件。



2

当我在2017年回答这个问题时,我对@SeanHammond的解决方案表示怀疑,因为rake gem已经安装好了。事实证明,这是通过Debian的rake软件包及其rubygems-integration系统完成的。根据Hammond先生的说法,今天再次安装rake gem对我有用,因为它覆盖了Debian的版本,因此避免了潜在的错误。好吧,首先它说:

martind@balance:~$ sudo gem2.1 install --no-ri --no-rdoc rake
Fetching: rake-12.3.1.gem (100%)
ERROR:  While executing gem ... (TypeError)
    no implicit conversion of nil into String
martind@balance:~$ 

在为错误报告应用上游修复程序之后,它表示:

rake's executable "rake" conflicts with an unknown executable
Overwrite the executable? [yN]  n
ERROR:  Error installing rake:
    "rake" from rake conflicts with installed executable from 
martind@balance:~$ 

...导致我成功:

martind@balance:~$ sudo gem2.1 install --no-ri --no-rdoc --format-executable rake
Successfully installed rake-12.3.1
1 gem installed
martind@balance:~$ 

这足以让rubygems找到更新的二进制文件:

martind@balance:~$ ruby2.1 -we 'puts(Gem.bin_path("rake", "rake"))'
/var/lib/gems/2.1.0/gems/rake-12.3.1/exe/rake
martind@balance:~$ ls -l /var/lib/gems/2.1.0/gems/rake-12.3.1/exe/rake
-rwxr-xr-x 1 root root 1182 Apr 17 15:03 /var/lib/gems/2.1.0/gems/rake-12.3.1/exe/rake
martind@balance:~$ 

@ShaunJackman的解决方案也对我有用。尽管我不想将文件留在计算机上的某个目录中,但以后要更改它,这可能是Debian应该修复它的方式。

rake=/usr/bin/rake在我想要安装的gem所在的环境中设置了一个较不痛苦的解决方法:

martind@balance:~$ rake=/usr/bin/rake sudo gem2.1 install --no-ri --no-rdoc mediawiki_api
Fetching: unf-0.2.0.beta2.gem (100%)
Building native extensions.  This could take a while...
Successfully installed unf-0.2.0.beta2
Fetching: mediawiki_api-0.7.1.gem (100%)
Successfully installed mediawiki_api-0.7.1
2 gems installed
martind@balance:~$ 

...如我的Debian错误报告中所述。您的sudo可能需要--preserve-env才能通过该设置。

(在该答案的较早版本中,我声称“等同于已sudo gem install rainbow解决的问题”,但事实证明,我的问题并不等同于我。问题不是与gem,rainbow和rubocop有关,而实际上与gem2.1,mediawiki-网关(或其后继程序mediawiki_api)和unf。之所以手动安装依赖项首先适用于我的情况,是因为gem2.1有一个bug,因此它倾向于将预发行版本安装为依赖项。我怀疑是从代码而非散文,那个虫子就是这个,当被要求自行安装unf时,它会正确地选择一个发行版,该发行版恰好是使用rubygem的ExtConfBuilder代码路径而不是RakeBuilder路径。那不会帮助原始海报解决彩虹问题,因为他们没有获得预发行版本。很抱歉,冗长的题外话,但可能会帮助其他面临类似问题的人。


1
对我来说甚至更简单:rake=rake工作
安东尼·索特尔
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.