Install pg gem on CentOS 6

I am trying to configure VPS (CentOS 6.4) using ruby ​​on rails and postgres.

I installed ruby ​​(2.1.0p0), rails (4.1.0) and postgresql (9.3.4) without any problems.

When I try to create a new rails application (rails new new_app -d postgresql), it stops when pg gem is installed. I looked at all the SO posts about this error and tried almost everything I could find. The most recommended was to run "yum install postgresql-devel" and still not work.

Below you can find the output ssh and mkmf.log. Let me know if you need more information ...


Output

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

 /home/deploy/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb
 checking for pg_config ... yes
 Using config values ​​from / usr / bin / pg_config
 checking for libpq-fe.h ... *** 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 / deploy / .rvm / rubies / ruby-2.1.0 / bin / ruby
     --with-pg
     --without-pg
     --with-pg-config
     --without-pg-config
     --with-pg_config
     --without-pg_config
     --with-pg-dir
     --without-pg-dir
     --with-pg-include
     --without-pg-include = $ {pg-dir} / include
     --with-pg-lib
     --without-pg-lib = $ {pg-dir} / lib
 /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:456:in `try_do ': The compiler failed to generate an executable file.  (RuntimeError)
 You have to install development tools first.
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rbβˆ—87:in `try_cpp '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1120:in `block in find_header '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb{51:in `block (2 levels) in postpone '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb{51:in `block in postpone '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb{47:in `postpone '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for '
     from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1119:in `find_header '
     from extconf.rb: 48: in ``

 extconf failed, exit code 1


mkmf.log

  "gcc -o conftest -I / home / deploy / .rvm / rubies / ruby-2.1.0 / include / ruby-2.1.0 / x86_64-linux -I / home / deploy / .rvm / rubies / ruby-2.1. 0 / include / ruby-2.1.0 / ruby ​​/ backward -I / home / deploy / .rvm / rubies / ruby-2.1.0 / include / ruby-2.1.0 -I. -I / usr / include -O3 - fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration- after-statement -Wimplicit-function-declaration -fPIC conftest.c -L. -L / home / deploy / .rvm / rubies / ruby-2.1.0 / lib -Wl, -R / home / deploy / .rvm / rubies /ruby-2.1.0/lib -L / usr / lib64 -Wl, -R / usr / lib64 -L. -fstack-protector -rdynamic -Wl, -export-dynamic -Wl, -rpath, '/ .. / lib '-Wl, -R -Wl,' / .. / lib '-L' /../ lib '-lruby -lpthread -lrt -ldl -lcrypt -lm -lc "
 gcc: error trying to exec 'as': execvp: Permission denied
 checked program was:
 / * begin * /
 1: #include "ruby.h"
 2:
 3: int main (int argc, char ** argv)
 4: {
 5: return 0;
 6:}
 / * end * /

+6
source share
6 answers

Since you are not using the outdated version of PostgreSQL that ships with CentOS 6 (PostgreSQL 8.4), you need to install the -devel package that matches your version (PostgreSQL 9.X).

The easiest way is to use the official PostgreSQL yum repository .

Since the latest version is 9.5 and is compatible with all versions of 9.X, I will write instructions for this. In the future, you can refer to the official instructions for updated teams.

 yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm yum install postgresql95-devel 

Then install the gem with the -with-pg-config option:

 gem install pg -- --with-pg-config=/usr/pgsql-9.5/bin/pg_config 
+5
source

Before:

For Centos 6: Install Postgres 9. * correctly with this guide .

After:

  yum install postgresql-libs postgresql-devel 

Useful instruction:

How to configure RoR using Postgres

+4
source

It was easier for me:

 ln -s /usr/pgsql-9.5/bin/pg_config /usr/local/bin/ 
+3
source

Try something like this:

 before "bundle:install" do run "ls -l #{fetch(:latest_release)}/Gemfile" #run "bundle config --local --gemfile=#{fetch(:latest_release)}/Gemfile build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config" run "cd #{fetch(:latest_release)} && bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config" end 
0
source

You can try installing pg gem with the postres pg_config file option:

 gem install pg -- --with-pg-config=/usr/pgsql-9.2/bin/pg_config 

Update the path to suit your system.

Hello

0
source

I had this problem on my mac and it was a bash / RVM problem. I had to add this to my bash: [[-s "$ HOME / .rvm / scripts / rvm"]] && & && & & & source "$ HOME / .rvm / scripts / rvm". Given that it finds the configuration file, I would look at that.

0
source

All Articles