Can't find the 'libpq-fe.h header when trying to install pg gem

前端 未结 30 1347
深忆病人
深忆病人 2020-11-22 07:47

I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error:



        
相关标签:
30条回答
  • 2020-11-22 08:13

    For CentOS 6.4,

    yum install postgresql-devel
    gem install pg
    

    worked well!

    0 讨论(0)
  • 2020-11-22 08:14

    On macOS (previously Mac OS X and OS X), use Homebrew to install the proper headers:

    brew install postgresql
    

    and then running

    gem install pg
    

    should work.

    Alternatively, instead of installing the whole postgresql, you can brew install libpq and export the correct PATH and PKG_CONFIG_PATH as explained in the 'Caveats' section

    0 讨论(0)
  • 2020-11-22 08:14

    A more general answer for any Debian-based distribution (which includes Ubuntu) is the following. First, install the apt-file package running as root:

    apt-get install apt-file
    

    This allows you to search for packages containing a file. Then, update its database using

    apt-file update
    

    (this can be run as normal user). Then, look for the missing header using:

    apt-file search libpq-fe.h
    

    On my machine, this gives:

    libpq-dev: /usr/include/postgresql/libpq-fe.h
    postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h
    

    There you go !

    0 讨论(0)
  • 2020-11-22 08:14

    For MacOS without installing PostgreSQL server:

    brew install libpq
    gem install pg -- --with-pg-config="/usr/local/Cellar/libpq/9.6.6/bin/pg_config"
    
    0 讨论(0)
  • 2020-11-22 08:14

    The location of libpq-fe.h depends on where your PostgreSQL install is (which depends on how you installed it). Use locate (http://en.wikipedia.org/wiki/Locate_%28Unix%29) to find the libpq-fe.h file on your machine. If it exists, it will be in the include directory of your PostgreSQL install.

    $ locate libpq-fe.h
    /Library/PostgreSQL/9.1/include/libpq-fe.h
    

    The bin directory, which contains pg_config, will be in the same directory as the include directory. As the error suggests, use the --with-pg-config option to install the gem:

    $ gem install pg --with-pg-config="/Library/PostgreSQL/9.1/bin/pg_config"
    

    Note that you may need to run updatedb if you have never used locate or if you haven't updated since installing PostgreSQL.

    0 讨论(0)
  • 2020-11-22 08:17

    Just for the record:

    Ruby on Rails 4 application in OS X with PostgresApp (in this case 0.17.1 version needed - kind of an old project):

    gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
    
    0 讨论(0)
提交回复
热议问题