Rails 3 -不能安装pg gem。

时间:2021-08-16 20:53:54

When I try to run bundle (bundle install), I all the time get

当我尝试运行bundle (bundle install)时,我总是得到。

Installing pg (0.13.2) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/ryan/.rvm/rubies/ruby-1.9.2-p290/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.

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=/Users/ryan/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config


Gem files will remain installed in /Users/ryan/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2 for inspection.
Results logged to /Users/ryan/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.13.2/ext/gem_make.out
An error occured while installing pg (0.13.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.13.2'` succeeds before bundling.

I use Mac OS X 10.6, the version of installed PostgreSQL is 9.1. I found the problem is in the libpq-dev, how could I install/fix that?

我使用Mac OS X 10.6,安装PostgreSQL的版本是9.1。我发现问题在libpq-dev中,我如何安装/修复它?

16 个解决方案

#1


75  

As stated in your error log you need to pass in the path to the pg_config. Try to install the gem using:

如您的错误日志中所述,您需要将路径传递到pg_config。尝试安装宝石使用:

gem install pg -- --with-pg-config= 'PATH_TO_YOUR_PG_CONFIG'

If you are not sure where your pg_config is, and assuming you are on Linux or Mac, you can run the following command:

如果您不确定pg_config在何处,并且假设您在Linux或Mac上,您可以运行以下命令:

which pg_config

Your pg-config can be in different locations depending on how you installed postgres.

您的pg-config可以在不同的位置,这取决于您如何安装postgres。

#2


97  

if you are running on Linux you may be interested in what worked for me:

如果你在Linux上运行,你可能会对我的工作感兴趣:

sudo apt-get install postgresql
sudo apt-get install libpq-dev

Then

然后

gem install pg

then

然后

bundle install

src: http://wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac

src:http://wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac

#3


56  

If you're using Postgress.app then youll want access to its command-line tools. Enter the following line in your terminal or your PATH profile:

如果你使用postgres。然后你会想要访问它的命令行工具。在您的终端或路径配置文件中输入以下行:

 PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

gem install pg should now work. (This is what worked for me.)

gem安装pg现在应该工作。(这就是我的工作。)

Note New versions path looks like:

注意,新的版本路径如下:

/Applications/Postgres.app/Contents/Versions/<version>/bin

#4


21  

If you have homebrew, just type:

如果你有家酿啤酒,请输入:

$ brew install postgresql

酿造安装postgresql美元

If you dont have it, download typing this in your terminal:

如果你没有,在你的终端下载这个:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

ruby -e“$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”

#5


12  

Search for libpq:

寻找libpq:

brew search libpq

Should output libpqxx

应该输出libpqxx

Then try install it:

然后试着安装:

brew install libpqxx

#6


7  

You only need to install libpq-dev:

您只需要安装libpq-dev:

sudo apt-get install libpq-dev

Then the gem should install just fine.

那么宝石应该安装得很好。

#7


7  

Follow the post-installation instructions: http://postgresapp.com/documentation/configuration-ruby.html

遵循安装后的指示:http://postgresapp.com/documentation/configur-ruby.html。

To install the pg gem, make sure you have set up your $PATH correctly (as specified in http://postgresapp.com/documentation/cli-tools.html), then run

要安装pg gem,请确保您正确设置了$PATH(如在http://postgresapp.com/documentation/cli-tools.html中指定),然后运行。

sudo ARCHFLAGS="-arch x86_64" gem install pg

sudo ARCHFLAGS="-arch x86_64" gem安装pg。

I strongly recommend reading both pages. Just skimmed them and lost 1 hour of my life. Read them, problem solved.

我强烈建议阅读这两页。我只是浏览了一下,失去了我生命中的一个小时。读他们,问题解决了。

#8


3  

The problem I had was that for some reason it was trying to compile with /usr/bin/gcc-4.2. I found that out by changing try_cpp in mkmf.rb (which I saw in the stack trace) to raise an exception with the compile line that was failing.

我遇到的问题是,由于某种原因,它试图用/usr/bin/gcc-4.2来编译。我通过在mkmf中更改try_cpp发现了这个问题。rb(我在堆栈跟踪中看到)用正在失败的编译线抛出异常。

I soft-linked gcc to gcc-4.2 and it worked:

我将gcc与gcc-4.2进行了软连接,并且成功了:

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

Why was it trying to use gcc-4.2? No idea.

为什么要使用gcc-4.2?不知道。

The actual compile line:

实际的编译:

/usr/bin/gcc-4.2 -E -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/backward -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/Cellar/postgresql/9.1.4/include  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration  -fno-common -pipe  conftest.c -o conftest.i (RuntimeError)

#9


3  

I got the same issue but my Postgres was install in

我遇到了同样的问题,但是我的Postgres安装了。

/Library/PostgreSQL/9.3

/图书馆/ PostgreSQL / 9.3

Updated the ~/.bash_profile by adding:

更新了~ /。bash_profile通过添加:

export PATH=/Library/PostgreSQL/9.3/bin:$PATH

Open a new terminal, run bundle update and also it worked for me. Thanks Ari.

打开一个新的终端,运行bundle update,它也适用于我。谢谢你阿里。

#10


1  

You can set a build config option bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config and use gem install pg without any options (the path to pg_config may be different for you, this one is for the Postgresapp 9.3.5.0)

您可以设置一个构建配置选项包配置构建。在没有任何选项的情况下(pg_config的路径对您来说可能是不同的,这一个是针对Postgresapp 9.3.5.0的)。

#11


1  

I had the same problem in my openSUSE13.1 KDE machine. Before that issue I encountered I had installed only the packages postgresql and postgresql-server using zypper command. Then installed again 2 more packages :

我在openSUSE13.1 KDE机器上遇到了同样的问题。在遇到这个问题之前,我使用了zypper命令只安装了postgresql和postgresql-服务器的包。然后再安装2个包:

[arup@to_do_app]$ sudo zypper in postgresql-devel postgresql-contrib
root's password:
Loading repository data...
Reading installed packages...
Resolving package dependencies...
#....

Then, I ran again bundle install, and success!!!

然后,我再次运行bundle安装,并成功!!!

#12


0  

For a working OSX solution see this guide http://krugerdavid.com/journal/how-to-install-xcode-homebrew-git-rvm-postgresql-ruby-1-9-3-on-snow-leopard/

对于一个工作OSX解决方案,请参阅本指南http://krugerdavid.com/journal/howto - installxcode - homebrewg -rvm-postgresql-ruby-1-9-3-on- - -雪豹。

It will walk you through installing PostgreSQL using homebrew. Tested and working for me on OSX 10.8.3, PostgreSQL 9.2.3, and Ruby 2.0.0-p0

它将引导您使用homebrew安装PostgreSQL。在OSX 10.8.3、PostgreSQL 9.2.3和Ruby 2.0.0-p0上测试和工作。

#13


0  

First, uninstall any Homebrew versions. The --force option makes it uninstall all versions.

首先,卸载任何自制版本。force选项使它卸载所有版本。

brew rm postgresql --force

Change paths accordingly for your version.

根据您的版本更改路径。

sudo /sbin/SystemStarter stop postgresql-8.4
sudo rm -rf /Applications/PostgreSQL\ 8.4
sudo rm -rf /etc/postgres-reg.ini
sudo rm -rf /Library/StartupItems/postgresql-8.4
sudo rm -rf /Library/PostgreSQL/8.4
sudo dscl . delete /users/postgres

Edit /etc/profile and delete any lines that reference "postgres".

编辑/etc/profile并删除任何引用“postgres”的行。

nano /etc/profile

Install PostgresSQL

安装PostgresSQL

brew update
brew install postgresql

Install de PG GEM

安装de PG宝石

gem install pg

That's it. Regards.

就是这样。的问候。

#14


0  

You can first check to see if you have a postrgresql file in your terminal by going to lib file. going cd ~/opt/local/lib/ and then type ls and the enter button. This will show you a list of all the files that are located in the lib directory.

您可以首先检查是否有一个postrgresql文件在您的终端,通过访问lib文件。进行cd ~/opt/local/lib/然后输入ls和enter按钮。这将显示在lib目录中所有文件的列表。

1.if you dont have postreseql you can download through macports. sudo port install postgresql93 @9.3.2_1

1。如果您没有postreseql,您可以通过macports下载。sudo端口安装postgresql93 @9.3.2_1。

Now cd back into your folder which you are trying to bundle install

现在,cd回到你的文件夹中,你正在尝试捆绑安装。

  1. getting your pg to work with your postgesql file you have or just downloaded gem install pg -- --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config
  2. 让您的pg与您的postgesql文件一起工作,或者刚刚下载了gem安装pg——with-pg-config=/opt/local/lib/postgresql93/bin/pg_config。

now run bundle install

现在运行包安装

#15


0  

On Fedora:

在Fedora:

dnf install postgresql-devel

#16


0  

What worked for me on El Capitan was upgrading ruby from the system default to 2.3.1 seemed to find the correct libraries that the pg gem needed.

在El Capitan上为我工作的是将ruby从系统默认升级到2.3.1,似乎找到了pg gem所需要的正确的库。

#1


75  

As stated in your error log you need to pass in the path to the pg_config. Try to install the gem using:

如您的错误日志中所述,您需要将路径传递到pg_config。尝试安装宝石使用:

gem install pg -- --with-pg-config= 'PATH_TO_YOUR_PG_CONFIG'

If you are not sure where your pg_config is, and assuming you are on Linux or Mac, you can run the following command:

如果您不确定pg_config在何处,并且假设您在Linux或Mac上,您可以运行以下命令:

which pg_config

Your pg-config can be in different locations depending on how you installed postgres.

您的pg-config可以在不同的位置,这取决于您如何安装postgres。

#2


97  

if you are running on Linux you may be interested in what worked for me:

如果你在Linux上运行,你可能会对我的工作感兴趣:

sudo apt-get install postgresql
sudo apt-get install libpq-dev

Then

然后

gem install pg

then

然后

bundle install

src: http://wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac

src:http://wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac

#3


56  

If you're using Postgress.app then youll want access to its command-line tools. Enter the following line in your terminal or your PATH profile:

如果你使用postgres。然后你会想要访问它的命令行工具。在您的终端或路径配置文件中输入以下行:

 PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

gem install pg should now work. (This is what worked for me.)

gem安装pg现在应该工作。(这就是我的工作。)

Note New versions path looks like:

注意,新的版本路径如下:

/Applications/Postgres.app/Contents/Versions/<version>/bin

#4


21  

If you have homebrew, just type:

如果你有家酿啤酒,请输入:

$ brew install postgresql

酿造安装postgresql美元

If you dont have it, download typing this in your terminal:

如果你没有,在你的终端下载这个:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

ruby -e“$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”

#5


12  

Search for libpq:

寻找libpq:

brew search libpq

Should output libpqxx

应该输出libpqxx

Then try install it:

然后试着安装:

brew install libpqxx

#6


7  

You only need to install libpq-dev:

您只需要安装libpq-dev:

sudo apt-get install libpq-dev

Then the gem should install just fine.

那么宝石应该安装得很好。

#7


7  

Follow the post-installation instructions: http://postgresapp.com/documentation/configuration-ruby.html

遵循安装后的指示:http://postgresapp.com/documentation/configur-ruby.html。

To install the pg gem, make sure you have set up your $PATH correctly (as specified in http://postgresapp.com/documentation/cli-tools.html), then run

要安装pg gem,请确保您正确设置了$PATH(如在http://postgresapp.com/documentation/cli-tools.html中指定),然后运行。

sudo ARCHFLAGS="-arch x86_64" gem install pg

sudo ARCHFLAGS="-arch x86_64" gem安装pg。

I strongly recommend reading both pages. Just skimmed them and lost 1 hour of my life. Read them, problem solved.

我强烈建议阅读这两页。我只是浏览了一下,失去了我生命中的一个小时。读他们,问题解决了。

#8


3  

The problem I had was that for some reason it was trying to compile with /usr/bin/gcc-4.2. I found that out by changing try_cpp in mkmf.rb (which I saw in the stack trace) to raise an exception with the compile line that was failing.

我遇到的问题是,由于某种原因,它试图用/usr/bin/gcc-4.2来编译。我通过在mkmf中更改try_cpp发现了这个问题。rb(我在堆栈跟踪中看到)用正在失败的编译线抛出异常。

I soft-linked gcc to gcc-4.2 and it worked:

我将gcc与gcc-4.2进行了软连接,并且成功了:

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

Why was it trying to use gcc-4.2? No idea.

为什么要使用gcc-4.2?不知道。

The actual compile line:

实际的编译:

/usr/bin/gcc-4.2 -E -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1/ruby/backward -I/Users/dfrankow/.rvm/rubies/ruby-1.9.3-p125/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/Cellar/postgresql/9.1.4/include  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration  -fno-common -pipe  conftest.c -o conftest.i (RuntimeError)

#9


3  

I got the same issue but my Postgres was install in

我遇到了同样的问题,但是我的Postgres安装了。

/Library/PostgreSQL/9.3

/图书馆/ PostgreSQL / 9.3

Updated the ~/.bash_profile by adding:

更新了~ /。bash_profile通过添加:

export PATH=/Library/PostgreSQL/9.3/bin:$PATH

Open a new terminal, run bundle update and also it worked for me. Thanks Ari.

打开一个新的终端,运行bundle update,它也适用于我。谢谢你阿里。

#10


1  

You can set a build config option bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config and use gem install pg without any options (the path to pg_config may be different for you, this one is for the Postgresapp 9.3.5.0)

您可以设置一个构建配置选项包配置构建。在没有任何选项的情况下(pg_config的路径对您来说可能是不同的,这一个是针对Postgresapp 9.3.5.0的)。

#11


1  

I had the same problem in my openSUSE13.1 KDE machine. Before that issue I encountered I had installed only the packages postgresql and postgresql-server using zypper command. Then installed again 2 more packages :

我在openSUSE13.1 KDE机器上遇到了同样的问题。在遇到这个问题之前,我使用了zypper命令只安装了postgresql和postgresql-服务器的包。然后再安装2个包:

[arup@to_do_app]$ sudo zypper in postgresql-devel postgresql-contrib
root's password:
Loading repository data...
Reading installed packages...
Resolving package dependencies...
#....

Then, I ran again bundle install, and success!!!

然后,我再次运行bundle安装,并成功!!!

#12


0  

For a working OSX solution see this guide http://krugerdavid.com/journal/how-to-install-xcode-homebrew-git-rvm-postgresql-ruby-1-9-3-on-snow-leopard/

对于一个工作OSX解决方案,请参阅本指南http://krugerdavid.com/journal/howto - installxcode - homebrewg -rvm-postgresql-ruby-1-9-3-on- - -雪豹。

It will walk you through installing PostgreSQL using homebrew. Tested and working for me on OSX 10.8.3, PostgreSQL 9.2.3, and Ruby 2.0.0-p0

它将引导您使用homebrew安装PostgreSQL。在OSX 10.8.3、PostgreSQL 9.2.3和Ruby 2.0.0-p0上测试和工作。

#13


0  

First, uninstall any Homebrew versions. The --force option makes it uninstall all versions.

首先,卸载任何自制版本。force选项使它卸载所有版本。

brew rm postgresql --force

Change paths accordingly for your version.

根据您的版本更改路径。

sudo /sbin/SystemStarter stop postgresql-8.4
sudo rm -rf /Applications/PostgreSQL\ 8.4
sudo rm -rf /etc/postgres-reg.ini
sudo rm -rf /Library/StartupItems/postgresql-8.4
sudo rm -rf /Library/PostgreSQL/8.4
sudo dscl . delete /users/postgres

Edit /etc/profile and delete any lines that reference "postgres".

编辑/etc/profile并删除任何引用“postgres”的行。

nano /etc/profile

Install PostgresSQL

安装PostgresSQL

brew update
brew install postgresql

Install de PG GEM

安装de PG宝石

gem install pg

That's it. Regards.

就是这样。的问候。

#14


0  

You can first check to see if you have a postrgresql file in your terminal by going to lib file. going cd ~/opt/local/lib/ and then type ls and the enter button. This will show you a list of all the files that are located in the lib directory.

您可以首先检查是否有一个postrgresql文件在您的终端,通过访问lib文件。进行cd ~/opt/local/lib/然后输入ls和enter按钮。这将显示在lib目录中所有文件的列表。

1.if you dont have postreseql you can download through macports. sudo port install postgresql93 @9.3.2_1

1。如果您没有postreseql,您可以通过macports下载。sudo端口安装postgresql93 @9.3.2_1。

Now cd back into your folder which you are trying to bundle install

现在,cd回到你的文件夹中,你正在尝试捆绑安装。

  1. getting your pg to work with your postgesql file you have or just downloaded gem install pg -- --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config
  2. 让您的pg与您的postgesql文件一起工作,或者刚刚下载了gem安装pg——with-pg-config=/opt/local/lib/postgresql93/bin/pg_config。

now run bundle install

现在运行包安装

#15


0  

On Fedora:

在Fedora:

dnf install postgresql-devel

#16


0  

What worked for me on El Capitan was upgrading ruby from the system default to 2.3.1 seemed to find the correct libraries that the pg gem needed.

在El Capitan上为我工作的是将ruby从系统默认升级到2.3.1,似乎找到了pg gem所需要的正确的库。