首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Rails:安装pg gem时出错

Rails:安装pg gem时出错
EN

Stack Overflow用户
提问于 2012-07-12 02:38:27
回答 4查看 34.7K关注 0票数 21

可能重复:

Postgres - the last version 0.14.0 of the “pg” gem gives error

我是rails的新手。我想使用PostgreSQL,因为Heroku也使用它,但是我在安装pg gem时遇到了麻烦。显然,有些文件丢失了,Makefile无法创建?

我的gem文件如下所示:

代码语言:javascript
复制
source 'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'faker', '1.0.1'
gem 'pg', '0.12.2'
gem 'json'

group :development, :test do
  gem 'rspec-rails', '2.10.0'
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails', '2.0.0'

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '1.4.0'
end

当我运行bundle install时,我在安装pg gem时得到以下错误:

代码语言:javascript
复制
    Installing pg (0.14.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
checking for pg_config... yes
Using config values from /usr/local/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... 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.

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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/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
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /Users/KennyGWang/.bundler/tmp/18833/gems/pg-0.14.0 for inspection.
Results logged to /Users/KennyGWang/.bundler/tmp/18833/gems/pg-0.14.0/ext/gem_make.out
An error occured while installing pg (0.14.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.0'` succeeds before bundling.

我使用自制的brew install postgresql安装了postgresql,因此which psql提供了/usr/local/bin/psql

如有任何帮助,我们不胜感激!

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-07-12 03:32:21

你用的是Mac电脑吗?如果是这样的话-最简单的方法是

  1. 确保已安装Xcode (可从应用程序商店获取)
  2. 在应用程序的根目录或gem install pg

中使用Homebrew

  • brew install postgresql

  • gem uninstall pg

  • either bundle install
票数 79
EN

Stack Overflow用户

发布于 2012-07-12 03:42:15

安装postgresql的步骤

  1. Install PostgreSQL及其库

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

  1. 安装后为postgresql创建用户

sudo postgres创建用户--超级用户$USER

sudo -u postgres创建用户pgs_root

  1. 为postgresql用户设置用户密码

sudo -u postgres psql postgres --设置"user=$USER“用户\密码: postgres=#

sudo -u postgres psql postgres postgres=# \passsword pgs_root

  1. 将postgresql.conf文件配置为使PostgreSQL侦听本地主机或侦听外部IP或其他内容,请将此行更改为IP或' localhost‘

gedit /etc/postgresql/8.4//postgresql.conf listen_addresses =‘本地主机’

与mysql查询浏览器一样,postgresql也有一个名为pgadmin的GUI。要安装,请运行以下命令

代码语言:javascript
复制
sudo apt-get install pgadmin3
票数 8
EN

Stack Overflow用户

发布于 2012-07-12 02:44:14

尝试包含此内容,而不是pg

代码语言:javascript
复制
gem install postgres-pr

代码语言:javascript
复制
gem install ruby-pg

编辑

你已经这么做了吗?

代码语言:javascript
复制
$ sudo apt-get install postgresql

$ rails new pg -d postgres

http://www.funonrails.com/2011/03/getting-started-with-rails-3-postgres.html

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11439207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档