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

前端 未结 30 1477
深忆病人
深忆病人 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:27

    I found this answer, and it was the only one that worked for me (Mac OS) - after researching for about two days:

    $ sudo su
    
    $ env ARCHFLAGS="-arch x86_64" gem install pg
    
    Building native extensions.  This could take a while...
    Successfully installed pg-0.11.0
    1 gem installed
    Installing ri documentation for pg-0.11.0...
    Installing RDoc documentation for pg-0.11.0...
    

    See Stack Overflow question Can't find the PostgreSQL client library (libpq).

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

    The right answer for Mac users with Postgres.app is to build against the libpq provided with that package. For example, with the 9.4 release (current as of this writing), all you need is:

    export CONFIGURE_ARGS="with-pg-include=/Applications/Postgres.app/Contents/Versions/9.4/include"
    gem install pg
    

    This will keep your pg gem in sync with exactly the version of PostgreSQL you have installed. Installing something from Homebrew is a waste in this case.

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

    On Debian 7.0, 64-bit (Wheezy), just run:

    sudo apt-get install libpq-dev
    

    After you successfully installed libpq-dev, run:

    bundle install
    
    0 讨论(0)
  • 2020-11-22 08:32

    I encountered the same error with postgres installed through asdf. The pg-config solutions didn't work for me. Instead I had to locate the postgres include folder which contains the file and run the command with the --with-pg-include flag

    gem install pg -- --with-pg-include=/<path>/.asdf/installs/postgres/<version>/include
    
    0 讨论(0)
  • 2020-11-22 08:33

    I am running Postgres.app on a Mac and I had to

    export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
    

    first. Then

    bundle install
    

    worked for me.

    0 讨论(0)
  • My solution for Fedora 30:

    sudo dnf install /usr/include/libpq-fe.h
    
    0 讨论(0)
提交回复
热议问题