I just installed Rails 4.0.2
and when creating a new app, in the bundle stage I get:
我刚安装了Rails 4.0.2,当我创建一个新的应用时,在bundle阶段我得到:
Installing pg (0.17.1)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/Dee/.rvm/rubies/ruby-2.0.0-p247/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.
How do I fix this?
我怎么解决这个问题?
13 个解决方案
#1
119
I'm on a Mac running Mavericks. My solution was to install Postgres.
我在Mac电脑上跑小牛队。我的解决方案是安装Postgres。
And then in terminal install using homebrew with the configuration:
然后在终端安装中使用homebrew配置:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
Note: This answer has been edited to use the latest
symlink that is currently included in shipping versions of the Postgres app.
注意:此答案已经过编辑,以使用当前在Postgres应用程序的shipping版本中包含的最新symlink。
Previous versions suggested:
以前的版本,建议:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
#2
140
Some kind of error resported here Installing PG gem on OS X - failure to build native extension
在OS X上安装PG gem时出现了一些错误,无法构建本机扩展。
To install dependencies on Ubuntu try this:
要在Ubuntu上安装依赖项,请尝试:
sudo apt-get install libpq-dev
and this
这
gem install pg
#3
16
app root:
应用程序根:
- brew update
- 酿造更新
- brew install postgres
- 酿造安装postgres
- gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
- gem安装pg -- -配置=/usr/本地/地下室/postgresql/9.3.4/bin/pg_config。
- bundle install
- 包安装
- ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
- ln -sfv /usr/local/opt/postgresql/*.plist ~ /图书馆/ LaunchAgents
- launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
- ~ /图书馆/ LaunchAgents / homebrew.mxcl.postgresql.plist launchctl负载
- createuser -s -r postgres
- createuser - s - r postgres
- rake db:create:all
- rake db:创建:所有
- rake db:migrate
- rake db:migrate
- rails s
- rails的年代
NOTE: replace the version number in step 3 if needed.
注意:如果需要,请在步骤3中替换版本号。
#4
11
Previously working answer with older version
I installed under mac OSX Mavericks, having the postgres app (Version 9.2.2.0 ) from www.postgresapp.com installed. The underlying problem was simpy that the since postgres was installed via the app, the configuration file resides on a location which is not the default one when installing it without postgressapp. so we need to tell gem where to find this file by:
我安装在mac OSX Mavericks下,从www.postgresapp.com安装了postgres应用程序(9.2.2.0版)。潜在的问题是simpy,因为postgres是通过应用程序安装的,配置文件驻留在一个位置上,在安装它时没有postgressapp,这不是默认的。所以我们需要告诉gem在哪里找到这个文件:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
gem安装pg -- -配置=/ application /Postgres.app/Contents/MacOS/bin/pg_config。
Hope it helps
希望它能帮助
#5
5
If gem install pg fails, try the following command:
如果gem安装pg失败,请尝试以下命令:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
... from the PostgreSQL.app Documentation
…PostgreSQL。应用程序文档
#6
3
Looks like you do not have PostgreSQL installed. The pg
gem requires some headers from PostgreSQL to compile native extension.
看起来您没有安装PostgreSQL。pg gem需要一些来自PostgreSQL的头文件来编译原生扩展。
#7
3
I had to combine everything and use
我必须把所有的东西结合起来使用。
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
#8
1
If you are using something other than Postgres in development and Postgres in production only, you can add the pg gem to your gemfile like so...
如果您使用的是开发中的Postgres和仅生产的Postgres,那么您可以将pg gem添加到gemfile中,这样…
group :production do
gem 'pg', '0.17.1'
end
Then use bundle install --without production
然后使用捆绑包安装——不需要生产。
#9
0
After installing Postgres I had to run the following command
安装Postgres后,我必须运行以下命令。
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
After this bundle install works great!
在这个bundle安装之后,效果很好!
Hope it helps
希望它能帮助
#10
0
The way I managed to get past that error was:
我设法克服这个错误的方法是:
- cd to app folder and then set the ruby version locally. I'm using ruby 2.1.2.
- cd到app文件夹,然后在本地设置ruby版本。我使用ruby 2.1.2。
rbenv local 2.1.2
rbenv当地2.1.2
- instead of just running bundle install, install the gems in vendor/bundle
- 不要只运行bundle安装,而是在供应商/bundle中安装gem。
bundle install --path vendor/bundle
包安装——路径供应商/包
This did it for me.
这是为我做的。
#11
0
I needed to use sudo
我需要用sudo。
sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
#12
0
For CentOS users:
CentOS的用户:
sudo yum install postgresql-devel
and
和
gem install pg
#1
119
I'm on a Mac running Mavericks. My solution was to install Postgres.
我在Mac电脑上跑小牛队。我的解决方案是安装Postgres。
And then in terminal install using homebrew with the configuration:
然后在终端安装中使用homebrew配置:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
Note: This answer has been edited to use the latest
symlink that is currently included in shipping versions of the Postgres app.
注意:此答案已经过编辑,以使用当前在Postgres应用程序的shipping版本中包含的最新symlink。
Previous versions suggested:
以前的版本,建议:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
#2
140
Some kind of error resported here Installing PG gem on OS X - failure to build native extension
在OS X上安装PG gem时出现了一些错误,无法构建本机扩展。
To install dependencies on Ubuntu try this:
要在Ubuntu上安装依赖项,请尝试:
sudo apt-get install libpq-dev
and this
这
gem install pg
#3
16
app root:
应用程序根:
- brew update
- 酿造更新
- brew install postgres
- 酿造安装postgres
- gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
- gem安装pg -- -配置=/usr/本地/地下室/postgresql/9.3.4/bin/pg_config。
- bundle install
- 包安装
- ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
- ln -sfv /usr/local/opt/postgresql/*.plist ~ /图书馆/ LaunchAgents
- launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
- ~ /图书馆/ LaunchAgents / homebrew.mxcl.postgresql.plist launchctl负载
- createuser -s -r postgres
- createuser - s - r postgres
- rake db:create:all
- rake db:创建:所有
- rake db:migrate
- rake db:migrate
- rails s
- rails的年代
NOTE: replace the version number in step 3 if needed.
注意:如果需要,请在步骤3中替换版本号。
#4
11
Previously working answer with older version
I installed under mac OSX Mavericks, having the postgres app (Version 9.2.2.0 ) from www.postgresapp.com installed. The underlying problem was simpy that the since postgres was installed via the app, the configuration file resides on a location which is not the default one when installing it without postgressapp. so we need to tell gem where to find this file by:
我安装在mac OSX Mavericks下,从www.postgresapp.com安装了postgres应用程序(9.2.2.0版)。潜在的问题是simpy,因为postgres是通过应用程序安装的,配置文件驻留在一个位置上,在安装它时没有postgressapp,这不是默认的。所以我们需要告诉gem在哪里找到这个文件:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
gem安装pg -- -配置=/ application /Postgres.app/Contents/MacOS/bin/pg_config。
Hope it helps
希望它能帮助
#5
5
If gem install pg fails, try the following command:
如果gem安装pg失败,请尝试以下命令:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
... from the PostgreSQL.app Documentation
…PostgreSQL。应用程序文档
#6
3
Looks like you do not have PostgreSQL installed. The pg
gem requires some headers from PostgreSQL to compile native extension.
看起来您没有安装PostgreSQL。pg gem需要一些来自PostgreSQL的头文件来编译原生扩展。
#7
3
I had to combine everything and use
我必须把所有的东西结合起来使用。
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
#8
1
If you are using something other than Postgres in development and Postgres in production only, you can add the pg gem to your gemfile like so...
如果您使用的是开发中的Postgres和仅生产的Postgres,那么您可以将pg gem添加到gemfile中,这样…
group :production do
gem 'pg', '0.17.1'
end
Then use bundle install --without production
然后使用捆绑包安装——不需要生产。
#9
0
After installing Postgres I had to run the following command
安装Postgres后,我必须运行以下命令。
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
After this bundle install works great!
在这个bundle安装之后,效果很好!
Hope it helps
希望它能帮助
#10
0
The way I managed to get past that error was:
我设法克服这个错误的方法是:
- cd to app folder and then set the ruby version locally. I'm using ruby 2.1.2.
- cd到app文件夹,然后在本地设置ruby版本。我使用ruby 2.1.2。
rbenv local 2.1.2
rbenv当地2.1.2
- instead of just running bundle install, install the gems in vendor/bundle
- 不要只运行bundle安装,而是在供应商/bundle中安装gem。
bundle install --path vendor/bundle
包安装——路径供应商/包
This did it for me.
这是为我做的。
#11
0
I needed to use sudo
我需要用sudo。
sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
#12
0
For CentOS users:
CentOS的用户:
sudo yum install postgresql-devel
and
和
gem install pg