51

My Rails is 3.2.1.4, Ruby is 1.9.3p448.

I got an error when I install ruby-debug:

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

    /home/hxh/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb
Can't handle 1.9.x yet
*** 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=/home/hxh/.rvm/rubies/ruby-1.9.3-p448/bin/ruby


Gem files will remain installed in /home/hxh/.rvm/gems/ruby-1.9.3-p448/gems/linecache-0.46 for inspection.
Results logged to /home/hxh/.rvm/gems/ruby-1.9.3-p448/gems/linecache-0.46/ext/gem_make.out

Who can tell me where the error is?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
HXH
  • 1,643
  • 4
  • 19
  • 31

15 Answers15

20

The error is in the mkmf.log file. That file should be located at /home/hxh/.rvm/gems/ruby-1.9.3-p448/gems/linecache-0.46/ext/linecache/mkmf.log.

If not, you can use

sudo find / -name mkmf.log

to find it.

To troubleshoot further, see "How to install Nokogiri Ruby gem with mkmf.log saying libiconv not found?"

Community
  • 1
  • 1
skibum55
  • 276
  • 2
  • 11
  • 1
    But what about when there is no mkmf.log file for the gem in question? For me, there's mkmf.log files for many other gems but not the one that's having a problem. – levininja Aug 18 '16 at 21:46
  • @levininja did you get any extra info in the error message? near the bottom i got `To see why this extension failed to compile, please check the mkmf.log which can be found here: ...` followed by a full path to the specific `.log` file – Owen Sep 18 '16 at 00:47
  • Like I said there was no mkmf.log file in the location it specified. I think I ended up restarting everything and the problem went away. – levininja Sep 19 '16 at 16:51
20

I am using Mac El Capitan. In my case it was caused by the missing developer tool. I solved it by installing the developer tool via xcode-select --install. After that bundle install worked fine again.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Guster
  • 1,733
  • 1
  • 16
  • 18
18

You're most likely missing some file headers (e.g. zlib or libiconv), so try installing them.

Linux: sudo apt-get install libz-dev libiconv-hook1 libiconv-hook-dev

OS X: brew install libiconv && xcode-select --install

Otherwise check your mkmf.log file for more specific details.

kenorb
  • 155,785
  • 88
  • 678
  • 743
8

I was facing the same issue running MacOS Big Sur version 11.1 and Xcode Version 12.4 (12D4e). In my case there was no command-line tool selected in Xcode.

I just followed the following steps to fix the problem:

  1. Start Xcode.
  2. Open the preferences using +,.
  3. Select the Locations tab.
  4. Select command-line tool (Xcode 12.4 12D4E in my case).
  5. Run sudo gem install cocoapods (in my case).

enter image description here

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Usama Azam
  • 403
  • 5
  • 13
6

It seems to be a issue with permission of gcc.. however, if you're using OS X, you may encounter this issue if you've updated your XCode but haven't agree to their terms & conditions yet.. try typing gcc in your terminal would show you what if you've agreed.

songyy
  • 4,323
  • 6
  • 41
  • 63
4

My mkmf.log showed that gcc (4.8.2 I think) didn't like a specific argument that was being used by atomic on

$ gem install atomic

So I had a very similar situation. The answer for me was to upgrade gcc/gcc-libs and lib tool.

I use Arch linux, and only Arch linux. The proper way to do this is to run

$ sudo pacman -Syu

which upgrades all system packages.

I installed Rails and hadn't run a system update since, which is where the issue came from. In most other *nix distros, you would update to the latest version of these packages by name, i.e. with apt, it would be something along the lines of

$ sudo apt-get update

followed by

$ sudo apt-get upgrade {package-name}
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
humbolight
  • 680
  • 4
  • 13
4

For what it's worth, using Ruby 2.0.0 I was having this problem on OSX 10.10.

I ended up running brew update, which resolved some conflicts, then installed the gem and it was fine.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
etusm
  • 4,082
  • 1
  • 30
  • 26
4

The answer of kenorb worked for me on Ubuntu 16.04 when I was trying installing rails! Thanks! I followed these steps below for installing rails:

  1. sudo apt-get install ruby-full
  2. sudo apt-get install libz-dev libiconv-hook1 libiconv-hook-dev
  3. sudo gem install rails
heronsanches
  • 524
  • 7
  • 12
  • facing same issue in LinuxMint. I can install rails after follow your instruction. Thanks1 – BimoS Dec 25 '17 at 04:09
4

I had the issue because gcc wasn't available on my machine.

Fixed it by installing gcc.

sudo apt install build-essential
Floris Devreese
  • 3,127
  • 2
  • 21
  • 31
2

This worked for me. Nokogiri was the problem.

Try the following if you are using Alpine-Linux(or equivalent command for your OS):

apk add build-base

And then install Nokogiri using:

gem install nokogiri -- --without-pkg-config --with-libxml-2.0-config
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Dhivya Dandapani
  • 401
  • 1
  • 5
  • 8
2

Took me a while to successfully install it.

  1. Install cocoapods with HomeBrew brew install cocoapods && brew link --overwrite cocoapods
  2. Verify your cocoapods version pod --version
parse
  • 1,706
  • 17
  • 27
1

This is probably happening because your computer has an older version of Ruby, so first update Ruby. This worked for Ruby 2.6.3+.

Open terminal and enter:

curl -L https://get.rvm.io | bash -s stable

Then:

rvm install ruby-2.6

This will install Ruby for you if it wasn't already installed, then update Ruby to the new version:

rvm use ruby-2.6.3

This will possibly fix your issue. You can now enter:

sudo gem install cocoapods
pod setup

If RVM is not installed in your system, then use:

$HOME/.rvm/scripts/rvm
rvm
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Vikash Sinha
  • 869
  • 1
  • 7
  • 21
-1

The problem is resolved with next command: sudo apt install build-essential

-1

Install RVM and use it to install Ruby 2.6.x:

curl -sSL https://get.rvm.io | bash
rvm install 2.6.x
rvm use ruby-2.6.x

Now try and it should work:

sudo gem install cocoapods
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Sishu
  • 1,510
  • 1
  • 21
  • 48
-1

This worked for me:

sudo apt-get install libmysqlclient-dev
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Sahil
  • 1
  • Welcome to SO! Please read "[answer]" and "[Explaining entirely code-based answers](https://meta.stackoverflow.com/q/392712/128421)". While this might be technically correct it doesn't explain why it solves the problem or should be the selected answer. We should educate along with helping solve the problem. In particular, explain why installing the MySQL-client dev help, especially since its a very round-about way of solving the problem. – the Tin Man Jan 30 '22 at 21:06