pg gem install fails - ruby-on-rails

Centos 6.9
(similar to question: Can't find the PostgreSQL client library (libpq) but that one is on MacOS not Centos, so those solutions did not work
ruby 2.1.8 (tried 2.2)
rails 4.2.6 (tried 5.0)
postgres 9.3
I am trying to install the pg gem with:
gem install pg -- --with-pqlib=/usr/lib64/libpqxx-4.0.so --with-pg-config=/usr/pgsql-9.3/bin/pg_config
I keep trying to feed it different libraries but the one it is getting stuck on is some PQconnectdb() function. Error below
Rails used to be installed on this computer with pg but something happend after an update.. Any ideas here?
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /home/myusername/.rvm/gems/ruby-2.1.8/gems/pg-0.14.1/ext
/home/myusername/.rvm/rubies/ruby-2.1.8/bin/ruby -r ./siteconf20170425-12873-191077o.rb extconf.rb --with-pqlib=/usr/lib64/libpqxx-4.0.so --with-pg-config=/usr/pgsql-9.3/bin/pg_config
Using config values from /usr/pgsql-9.3/bin/pg_config
extconf.rb:34: warning: Insecure world writable dir /opt/anaconda in PATH, mode 040777
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -l/usr/lib64/libpqxx-4.0.so... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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.
Installed pg libraries:Installed Packages
postgresql93.x86_64 9.3.16-1PGDG.rhel6
postgresql93-contrib.x86_64 9.3.16-1PGDG.rhel6
postgresql93-debuginfo.x86_64 9.3.16-1PGDG.rhel6
postgresql93-devel.x86_64 9.3.16-1PGDG.rhel6
postgresql93-docs.x86_64 9.3.16-1PGDG.rhel6
postgresql93-libs.x86_64 9.3.16-1PGDG.rhel6
postgresql93-odbc.x86_64 09.06.0100-1PGDG.rhel6
postgresql93-odbc-debuginfo.x86_64 09.03.0400-1PGDG.rhel6
postgresql93-plperl.x86_64 9.3.16-1PGDG.rhel6
postgresql93-plpython.x86_64 9.3.16-1PGDG.rhel6
postgresql93-pltcl.x86_64 9.3.16-1PGDG.rhel6
postgresql93-server.x86_64 9.3.16-1PGDG.rhel6
postgresql93-tcl.x86_64 2.1.1-1.rhel6
postgresql93-tcl-debuginfo.x86_64 2.1.1-1.rhel6
postgresql93-test.x86_64 9.3.16-1PGDG.rhel6

Have you tried this?
$ sudo su
$ env ARCHFLAGS="-arch x86_64" gem install pg

I had a linux brew package manager, which had some old dependencies that messed with the pg gem install.
The answer is:
Remove [linux brew][1]
[1]: http://linuxbrew.sh/
Uninstall Ruby With RVM
Implode RVM
Reinstall RVM
Reinstall ruby
Install pg gem with a pg config option:
gem install pg -- --with-pg-config=/usr/pgsql-9.3/bin/pg_config

Related

Install PG gem in OpenSUSE

283
65
I'm trying to install PostgreSQL's pg gem for Ruby.
I issued the following command:
gem install pg
I installed Ruby 1.9.2 using RVM.
The above command shows me the following error.
The error is :
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby extconf.rb
checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
etc...
Somebody gave solution for Ubuntu users.
What about OpenSUSE Linux?
Thanks for advance.
For me this was the solution:
zypper in postgresql-server-devel
pg_config is part of postgresql-server-devel, if you install that
package then it should work on Tumbleweed at least.
Source: https://lists.opensuse.org/opensuse-factory/2019-03/msg00300.html
As per my search OpenSUSE linux has no package for client of Postgres, but as you have installed that it, that mean chances are the file pgsql.so is present in your system. How did you install it, I can see following which says it will install development libraries and client also
sudo zypper in postgresql postgresql-server postgresql-contrib
sudo zypper in postgresql-plperl postgresql-plpython postgresql-plctl
If this does not work then try to search in postgres installation path this file, locate file_name is easy to find files on different linux, but not sure it works in openSUSE it is part of mlocate package. If you find that file then symbol link it as per error, where error is searching this file.
If it is still not working, then you can use your Postgres directory in environment variable and try to install gem individually. To get postgres configuration use following command to see directories.
pg_config
Now try to install gem
PATH=$PATH:/Library/PostgreSQL/9.0/bin sudo gem install pg
On some system following command also resolve issue, so you can try it too
sudo gem install pg – --with-pg-config=/usr/local/pgsql/bin/pg_config

postgresql gem with ruby 2.0.0-p353 on mac wont suceed

I'm trying to bundle a new rails app using Postgres.
I get this error each time I try to bundle.
Errno::EACCES: Permission denied - /usr/local/var/rbenv/versions/2.0.0- p353/lib/ruby/gems/2.0.0/gems/pg-0.17.0/.gemtest
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.0'` succeeds before bundling.
When I try to install the pg gem with sudo it says:
➜ wandrr sudo gem install pg -v '0.17.0'
Password:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/usr/local/var/rbenv/versions/2.0.0-p353/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.
I've read pg app's documentation and still not sure.
My zshrc file looks like this
# Customize to your needs...
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
export RBENV_ROOT=/usr/local/var/rbenv
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
I used homebrew to install rbenv and ruby-build.
I've check ruby gems is up to date aswel.
Any suggestions on how to get the pg gem to succeed?
SOLUTION FOUND
My initial problem of trying to get gem install pg to work was due to the postgres app not working right. The problem was fixed by checking the path set in my ZSHRC file.
Here's what it looks like now:
# Customize to your needs...
PATH=/Applications/Postgres93.app/Contents/MacOS/bin:$PATH
eval "$(rbenv init -)";
Note: the docs said to use
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
however the application in this instance is called Postgres93.app

Error while building bundle due to pg gem? [duplicate]

I just upgraded from OS X Lion to OS X Mountain Lion.
My rails environment for the most part stayed in tact.
The only steps I had to do to get things back to a good state was:
- Install XCode 4.4
- Install XCode 4.4 Command Line Tools
- Install gcc-4.2
So all that went well.
Here's the issue, almost all my gems install properly when I run bundle install except for one of the most important ones I need - the postgresql gem 'pg'.
And it specifically fails for versions above 0.12.2.
I'm using ruby 1.9.3p125.
I can successfully grab the 0.12.2 pg gem, and versions below, but they give me segmentation faults (I'm guessing because of the version of ruby I'm using).
So this leads me to believe that it's specific to the pg gem, and not my overall environment seeing as other gems install fine.
I also tried re-installing Postgresql to ensure my postgres environment is ok and seems good on that front.
Has anybody been able to install the 'pg' gem version 0.13.0 or above (and more preferrably 0.14.X)?
Here is my stack trace:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/caseyli/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for pg_char_to_encoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
checking for ruby/st.h... yes
creating extconf.h
creating Makefile
make
compiling pg.c
pg.c: In function ‘pg_s_library_version’:
pg.c:273: warning: implicit declaration of function ‘PQlibVersion’
pg.c: In function ‘Init_pg_ext’:
pg.c:384: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:384: error: (Each undeclared identifier is reported only once
pg.c:384: error: for each function it appears in.)
pg.c:386: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:388: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:390: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1
Gem files will remain installed in /Users/caseyli/.rvm/gems/ruby-1.9.3- p125#elliottfarmequipment/gems/pg-0.14.0 for inspection.
Deefour's comment got it! It was the way I installed PostgreSQL.
I use the PostgreSQL one-click installer which I'm guessing doesn't set up the libpq up properly for Mountain Lion.
Homebrew on the otherhand will build it properly for the OS.
After installing postgres through homebrew
brew install postgresql
I was able to install my gem no problem.
Thanks everybody!
The issue is the location of pg_config. If you use the one-click installer, it is in /Library/PostgreSQL/9.2/bin/pg_config, so this will build your gem just fine:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.2/bin/pg_config
I had the exact same issue; same stack trace as you've posted.
MRI 1.9.3-p286 / OS X 10.8.2 / Postgres 9.0.4 with homebrew.
I solved it by simply doing:
$ brew update
$ brew upgrade postgresql
$ bundle
Hope it works for someone else.
Reinstalling ruby fixed a similar issue I was having after upgrading to Mountain Lion
rvm reinstall 1.9.3
Note: also run the following as it seems the default version resets
rvm --default 1.9.3
For reference I posted the error I was seeing below
gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with pg=/usr/local/Cellar/postgresql/9.1.4/bin
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Mac comes with an outdated prebuilt PostgreSQL client installation and pg_config file that comes with it conflicts with any new PostgreSQL server & client installations.
Installing ruby gem with a fully qualified file name of pg_config overrides default known location of pg_config and installation succeeds.
Current location of pg_config by one click installer by EnterpriseDB: /Library/PostgreSQL/bin/pg_config
This command finally worked for me.
CrashMX2$ gem install pg -- --with-pg-config=/Library/PostgreSQL/bin/pg_config
I have had the same problem but reinstalling postgresql with homebrew did not solve it. However, this command did it for me:
sudo env ARCHFLAGS="-arch x86_64" gem install pg
I was able to get it to work by installing the Postgres.app from Heroku and removing my existing postgresql installation. You can download the app here:
http://postgresapp.com/
brew remove postgresql
bundle install
If you didn't use brew, here's a link to more uninstall docs from Postgres.app
http://postgresapp.com/documentation#toc_16
I just got mine up and running via this ticket:
How can I pass a parameter for gem installation when I run bundle install?
bundle config build.pg --with-pg-config=/path/to/pg_config
bundle install
Like Matt, Ranjan, and Peter Mellett all say, you have to get the right pg_config location, and Mountain Lion comes with a different location that doesn't seem to play well with rubygems, so if you find your old version like
/Library/PostgreSQL/bin/pg_config
then you can set that in the bundle config before installing.
My situation was upgrading from Lion to Mountain Lion.
Homebrew installed pg_ctl in /usr/local/bin/pg_ctl, so the command for me was:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_ctl
Fro those, who are using Kubuntu 13.04 and installed pg with one click tool, pg config is in other folder, so command:
gem install pg -- --with-pg-config=/opt/PostgreSQL/9.3/bin/pg_config

pg gem '0.14.0' on Mountain Lion fails

I just upgraded from OS X Lion to OS X Mountain Lion.
My rails environment for the most part stayed in tact.
The only steps I had to do to get things back to a good state was:
- Install XCode 4.4
- Install XCode 4.4 Command Line Tools
- Install gcc-4.2
So all that went well.
Here's the issue, almost all my gems install properly when I run bundle install except for one of the most important ones I need - the postgresql gem 'pg'.
And it specifically fails for versions above 0.12.2.
I'm using ruby 1.9.3p125.
I can successfully grab the 0.12.2 pg gem, and versions below, but they give me segmentation faults (I'm guessing because of the version of ruby I'm using).
So this leads me to believe that it's specific to the pg gem, and not my overall environment seeing as other gems install fine.
I also tried re-installing Postgresql to ensure my postgres environment is ok and seems good on that front.
Has anybody been able to install the 'pg' gem version 0.13.0 or above (and more preferrably 0.14.X)?
Here is my stack trace:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/caseyli/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for pg_char_to_encoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
checking for ruby/st.h... yes
creating extconf.h
creating Makefile
make
compiling pg.c
pg.c: In function ‘pg_s_library_version’:
pg.c:273: warning: implicit declaration of function ‘PQlibVersion’
pg.c: In function ‘Init_pg_ext’:
pg.c:384: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:384: error: (Each undeclared identifier is reported only once
pg.c:384: error: for each function it appears in.)
pg.c:386: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:388: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:390: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1
Gem files will remain installed in /Users/caseyli/.rvm/gems/ruby-1.9.3- p125#elliottfarmequipment/gems/pg-0.14.0 for inspection.
Deefour's comment got it! It was the way I installed PostgreSQL.
I use the PostgreSQL one-click installer which I'm guessing doesn't set up the libpq up properly for Mountain Lion.
Homebrew on the otherhand will build it properly for the OS.
After installing postgres through homebrew
brew install postgresql
I was able to install my gem no problem.
Thanks everybody!
The issue is the location of pg_config. If you use the one-click installer, it is in /Library/PostgreSQL/9.2/bin/pg_config, so this will build your gem just fine:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.2/bin/pg_config
I had the exact same issue; same stack trace as you've posted.
MRI 1.9.3-p286 / OS X 10.8.2 / Postgres 9.0.4 with homebrew.
I solved it by simply doing:
$ brew update
$ brew upgrade postgresql
$ bundle
Hope it works for someone else.
Reinstalling ruby fixed a similar issue I was having after upgrading to Mountain Lion
rvm reinstall 1.9.3
Note: also run the following as it seems the default version resets
rvm --default 1.9.3
For reference I posted the error I was seeing below
gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with pg=/usr/local/Cellar/postgresql/9.1.4/bin
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Mac comes with an outdated prebuilt PostgreSQL client installation and pg_config file that comes with it conflicts with any new PostgreSQL server & client installations.
Installing ruby gem with a fully qualified file name of pg_config overrides default known location of pg_config and installation succeeds.
Current location of pg_config by one click installer by EnterpriseDB: /Library/PostgreSQL/bin/pg_config
This command finally worked for me.
CrashMX2$ gem install pg -- --with-pg-config=/Library/PostgreSQL/bin/pg_config
I have had the same problem but reinstalling postgresql with homebrew did not solve it. However, this command did it for me:
sudo env ARCHFLAGS="-arch x86_64" gem install pg
I was able to get it to work by installing the Postgres.app from Heroku and removing my existing postgresql installation. You can download the app here:
http://postgresapp.com/
brew remove postgresql
bundle install
If you didn't use brew, here's a link to more uninstall docs from Postgres.app
http://postgresapp.com/documentation#toc_16
I just got mine up and running via this ticket:
How can I pass a parameter for gem installation when I run bundle install?
bundle config build.pg --with-pg-config=/path/to/pg_config
bundle install
Like Matt, Ranjan, and Peter Mellett all say, you have to get the right pg_config location, and Mountain Lion comes with a different location that doesn't seem to play well with rubygems, so if you find your old version like
/Library/PostgreSQL/bin/pg_config
then you can set that in the bundle config before installing.
My situation was upgrading from Lion to Mountain Lion.
Homebrew installed pg_ctl in /usr/local/bin/pg_ctl, so the command for me was:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_ctl
Fro those, who are using Kubuntu 13.04 and installed pg with one click tool, pg config is in other folder, so command:
gem install pg -- --with-pg-config=/opt/PostgreSQL/9.3/bin/pg_config

make error when installing nokogiri gem using rvm on ruby-1.8.7-p334 [ x86_64 ]

When I try to install nokogiri gem on ruby-1.8.7-p334 [ x86_64 ] on Mac OS X 10.6, I get the following error:
sudo gem install nokogiri
/Users/patelc75/.rvm/rubies/ruby-1.8.7-p334/bin/gem:4: warning: Insecure world writable dir /Users in PATH, mode 040777
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/patelc75/.rvm/rubies/ruby-1.8.7-p334/bin/ruby extconf.rb
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
-----
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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.
Before installing nokogiri gem, you need to get libraries installed.
Here are the steps to do it with homebrew
# the rest of this snippet assumes installation of libxml 2.7.7. YMMV.
brew install libxml2
brew link libxml2
# install libxslt from source
wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
tar -zxvf libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 \
--with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.7
make
sudo make install
gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
With macports
sudo port install libxml2 libxslt
sudo gem install nokogiri
More information here http://nokogiri.org/tutorials/installing_nokogiri.html
I tries all kinds of solutions I can found, including:
. use brew to install libxslt / libxml2 / libiconv
. tries to gem install with various --with-configurations
sadly, they all didn't work for me, until I uninstalled MacPort and all installed ports.
Then simply executed command gem install nokogiri, the gem and rdoc got installed like a breeze.
I don't understand the very details of why, but according to my own experiences of using MacPort (resulted in multiple sets of ruby/rake/gem(s) installed) and articles comparing brew and port, I will not go back to port.

Resources