Ruby-on-rails Rails:安装 pg gem 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11439207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 03:40:47  来源:igfitidea点击:

Rails: Error installing pg gem

ruby-on-railspostgresql

提问by knygw

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

可能的重复:
Postgres - “pg” gem 的最新版本 0.14.0 给出错误

I'm new to rails. I want to use PostgreSQL since Heroku uses it too, but I'm having a bad time installing the pggem. Apparently, some files are missing and a Makefile cannot be created?

我是导轨的新手。我想使用 PostgreSQL,因为 Heroku 也使用它,但是我在安装pggem时遇到了麻烦。显然,某些文件丢失并且无法创建 Makefile?

My gem file looks like this:

我的 gem 文件如下所示:

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

And when I run bundle installI get the following error when installing the pg gem:

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

    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.

I installed postgresql using homebrew, brew install postgresql, thus which psqlgives me /usr/local/bin/psql

我使用自制软件安装了 postgresql brew install postgresql,因此which psql给了我/usr/local/bin/psql

Any help is appreciated!

任何帮助表示赞赏!

回答by plasticide

Are you on a Mac? If so - the easiest way to do this is to

你在 Mac 上吗?如果是这样 - 最简单的方法是

  1. make sure you have Xcode installed (you can get it from the app store)
  2. use Homebrew
  3. brew install postgresql
  4. gem uninstall pg
  5. either bundle installin your application's root or gem install pg
  1. 确保您已安装 Xcode(您可以从应用商店获取)
  2. 使用自制软件
  3. brew install postgresql
  4. gem uninstall pg
  5. 无论是bundle install在应用程序的根目录或gem install pg

回答by Addicted

Steps to install postgresql

安装 postgresql 的步骤

  1. Install PostgreSQL and its libraries

    sudo apt-get install postgresql postgresql-contrib libpq-dev
    
  2. After the installation create a user for postgresql

    sudo -u postgres createuser --superuser $USER
    

    or

    sudo -u postgres createuser pgs_root
    
  3. Set user password for the postgresql user

    sudo -u postgres psql postgres ( For psql prompt) postgres=# \passsword for ex.-      postgres=# \passsword pgs_root
    
  4. Configure the postgresql.conf file to make PostgreSQL listen to localhost or listen on an external IP or something, change this line to either the IP or 'localhost'

    gedit /etc/postgresql/8.4/main/postgresql.conf listen_addresses = 'localhost'
    
  1. 安装 PostgreSQL 及其库

    sudo apt-get install postgresql postgresql-contrib libpq-dev
    
  2. 安装后为 postgresql 创建一个用户

    sudo -u postgres createuser --superuser $USER
    

    或者

    sudo -u postgres createuser pgs_root
    
  3. 为 postgresql 用户设置用户密码

    sudo -u postgres psql postgres ( For psql prompt) postgres=# \passsword for ex.-      postgres=# \passsword pgs_root
    
  4. 配置 postgresql.conf 文件使 PostgreSQL 侦听 localhost 或侦听外部 IP 或其他内容,将此行更改为 IP 或“localhost”

    gedit /etc/postgresql/8.4/main/postgresql.conf listen_addresses = 'localhost'
    


Like mysql query browser, there is a GUI for postgresql called pgadmin. To install run this command

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

sudo apt-get install pgadmin3

回答by Hitham S. AlQadheeb

Try to include this instead of pg

尝试包含这个而不是 pg

gem install postgres-pr

or

或者

gem install ruby-pg

Edit

编辑

Did you do this already?

你已经这样做了吗?

$ sudo apt-get install postgresql

$ rails new pg -d postgres

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

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

回答by bento

have you checked the log mkmf.log as it was recommended in the error you've included?

您是否检查了日志 mkmf.log,因为它是您包含的错误中推荐的?

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.

由于某种原因无法创建 Makefile,可能缺少必要的库和/或头文件。检查 mkmf.log 文件以获取更多详细信息。您可能需要配置选项。