14

when I try "sudo gem install rubocop", I get...

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

So I have tried a number of solutions, specifically those from https://stackoverflow.com/questions/22544754/failed-to-build-gem-native-extension-installing-compass (different gem, same error)

I tried reinstalling RVM with "rvm reinstall --disable-binary 2.2.0" which took a while but didn't fix it

next i tried $ "sudo apt-get install ruby-dev" which yields

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.

I've also tried "gem update --system" to which I get...

Latest version currently installed. Aborting.

Any suggestions will be greatly appreciated as I am a total noob and I'm stuck.

2
  • As the error says, do you have rake installed?
    – muru
    Jan 16, 2017 at 4:11
  • Yep. I have the newest version.
    – user642832
    Jan 16, 2017 at 4:21

3 Answers 3

29

Do sudo gem install rake and then do sudo gem install rubocop again and it should work.

It doesn't seem to matter that you have the right version of rake installed. For me rake --version reported 10.5.0 but I was still getting the same error message as you.

Looking at the error message, it is looking for rake at a specific path, not just anywhere on 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 reports /usr/local/bin/rake, not /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake.

And in fact, as the error message says, there is no file at /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/rake.

This is probably to do with rake having been apt-get installed rather than gem installed. sudo gem install rake creates that file.

0
3

I was able to resolve this problem with

sudo mkdir -p /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin
sudo ln -s /usr/bin/rake /usr/share/rubygems-integration/all/gems/rake-10.5.0/bin/

See this commit on GitHub.

2

When I answered this in 2017, I was skeptical of @SeanHammond's solution, because the rake gem already appeared to be installed. That turns out to have been through Debian's rake package and their rubygems-integration system. Installing the rake gem again, per Mr Hammond, worked for me today, as it overrode Debian's version, hence avoided the underlying bug. Well, first it said:

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:~$ 

After I applied an upstream fix for the error reporting, that said:

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:~$ 

... which led me to succeed with:

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

That's enough for rubygems to find the updated binary:

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's solution worked for me too. That might well be the way that Debian should fix it, though I'd rather not leave files in a directory on my machine that Debian might later want to change.

A less painful work-around was setting rake=/usr/bin/rake in the environment from which I installed the gem I wanted:

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:~$ 

... as now noted in my Debian bug report. Your sudo might need --preserve-env to pass through that setting.

(In an earlier version of this answer, I claimed that "the equivalent of sudo gem install rainbow solved it" but it turns out that my problem was not equivalent. My problem wasn't with gem, rainbow and rubocop but actually with gem2.1, mediawiki-gateway (or its successor, mediawiki_api) and unf. The reason that installing the dependency manually first worked for my case was that gem2.1 has a bug whereby it prefers to install prerelease versions as dependencies. I suspect, from the code rather than the prose, that the bug is this one, When asked to install unf itself, it instead, and rightly, picks a release version, one that just happens to use rubygem's ExtConfBuilder code path rather than its RakeBuilder one. That wouldn't have helped the original poster with their rainbow problem, as they didn't get a prerelease version. Sorry for the lengthy digression, but perhaps it will help someone else facing a similar problem.)

1
  • 1
    even simpler for me: rake=rake worked May 21, 2018 at 19:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .