Rails:安装pg gem时出错

kny*_*ygw 18 postgresql ruby-on-rails

可能重复:
Postgres - "pg"gem的最后一个版本0.14.0会出错

我是铁杆新手.我想使用PostgreSQL,因为Heroku也使用它,但是我安装pg宝石的时间很糟糕.显然,有些文件丢失,无法创建Makefile?

我的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
Run Code Online (Sandbox Code Playgroud)

当我运行时,我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.
Run Code Online (Sandbox Code Playgroud)

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

任何帮助表示赞赏!

小智 67

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

  1. 确保安装了Xcode(您可以从应用商店获取)
  2. 使用Homebrew
  3. brew install postgresql
  4. gem uninstall pg
  5. 要么bundle install在应用程序的根目录中,要么在gem install pg

  • 只是为了增加这一点,当我遇到它搜索谷歌时,我在OSX Yosemite上遇到了类似的问题:上面的内容对我不起作用但是这样做了:http://stackoverflow.com/a/7497725/1945990 (2认同)

Add*_*ted 7

安装postgresql的步骤

  1. 安装PostgreSQL及其库

    sudo apt-get install postgresql postgresql-contrib libpq-dev
    
    Run Code Online (Sandbox Code Playgroud)
  2. 安装后为postgresql创建一个用户

    sudo -u postgres createuser --superuser $USER
    
    Run Code Online (Sandbox Code Playgroud)

    要么

    sudo -u postgres createuser pgs_root
    
    Run Code Online (Sandbox Code Playgroud)
  3. 设置postgresql用户的用户密码

    sudo -u postgres psql postgres ( For psql prompt) postgres=# \passsword for ex.-      postgres=# \passsword pgs_root
    
    Run Code Online (Sandbox Code Playgroud)
  4. 配置postgresql.conf文件以使PostgreSQL监听localhost或监听外部IP或其他东西,将此行更改为IP或"localhost"

    gedit /etc/postgresql/8.4/main/postgresql.conf listen_addresses = 'localhost'
    
    Run Code Online (Sandbox Code Playgroud)

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

sudo apt-get install pgadmin3
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

30174 次

最近记录:

10 年,2 月 前