Tag Archives: Ruby

Can’t find the ‘libpq-fe.h header

I need to install pg 0.17.1 gem on a server running CentOS. This is the error message I saw:

# gem install pg -v '0.17.1'
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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.
...

First thing came to my mind was I must have forgotten to install the -dev package.

# yum install postgresql93-devel

Then, when I ran gem command again, suprisingly I still got the same error message. So I checked the explanation in the error message carefully.

# locate pg_config
/usr/pgsql-9.3/bin/pg_config
/usr/pgsql-9.3/share/man/man1/pg_config.1

# gem install pg -v '0.17.1' -- --with-pg-config=/usr/pgsql-9.3/bin/pg_config

This time, pg gem was successfully installed.

Note, if you use bundle to install gem, you’ll need to run this command:

# bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config
# bundle install --path vendor/bundle

FIXED: extconf.rb:8:in `require’: no such file to load — mkmf (LoadError)

While reading Linux Journal Issue 181 today, I stumbled upon a section explaining about running Ruby on Rails on Apache using an Apache module called Phusion Passenger, also known as mod_rails.

To install Passenger, I followed the instruction provided in the magazine:

sudo gem install passenger

Unxpectedly, I got the following error:

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

/usr/bin/ruby1.8 extconf.rb
extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:8

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/fastthread-1.0.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/fastthread-1.0.7/ext/fastthread/gem_make.out

What’s happening? What did I do wrong?

According to a blog post by Al Hoang, a Ruby dev package needed to be installed. Well, I wouldn’t have a clue about this!

So, to FIX this, I need to install ruby1.8-dev:

$ sudo apt-get install ruby1.8-dev
...

Now, I’m ready to install Passenger gem:

$ sudo gem install passenger
Building native extensions. This could take a while...
Successfully installed passenger-2.2.4
1 gem installed
Installing ri documentation for passenger-2.2.4...
Installing RDoc documentation for passenger-2.2.4...

Credit: Fixing ‘mkmf’ load error Ruby in Ubuntu

Debian JSON for Ruby

I tried to install JSON for Ruby via RubyGem,

# gem install json

and I got the following error message:

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


/usr/bin/ruby1.8 extconf.rb install json
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/json-1.1.6 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/json-1.1.6/ext/json/ext/generator/gem_make.out

However, I found out in Debian, we can just install this library libjson-ruby:

$ sudo apt-get install libjson-ruby

Now, try to verify if it works:

$ irb
irb(main):001:0> require 'json'
=> true
irb(main):002:0>