ruby - Rails 错误运行 Gem 安装 PG

标签 ruby postgresql ruby-on-rails-4 rubygems

我正在尝试将我的应用程序推送到 Heroku,并且我这样配置了我的 gemfile:

group :production do
  gem 'pg', '0.18.4'
  gem 'rails_12factor', '0.0.2'
  gem 'puma'
end

当运行 bundle install 时,我的控制台出现这个错误:

An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.

然后当我运行 gem install pg -v '0.18.4' 时,我得到以下信息:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

当我运行 sudo gem install pg -v '0.18.4'

我得到以下信息:

ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.0.0/gems/pg-0.18.4/ext
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20160125-5501-ugsd1s.rb 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.

更新

我重新安装了 RVM 和 rails,现在当我运行 gem install pg -v '0.18.4' 时,它运行成功:

Successfully installed pg-0.18.4
Parsing documentation for pg-0.18.4
Done installing documentation for pg after 3 seconds
1 gem installed

但是当运行 bundle install 时,我得到这个:

Installing pg 0.18.4 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/benwong/Desktop/ruby/rails_projects/blog2/vendor/bundle/ruby/2.2.0/gems/pg-0.18.4/ext
/Users/benwong/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20160126-44660-1ufenyc.rb extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/MacOS/bin/pg_config
sh: /Applications/Postgres.app/Contents/MacOS/bin/pg_config: No such file or directory
sh: /Applications/Postgres.app/Contents/MacOS/bin/pg_config: No such file or directory
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... yes
checking for PQconnectionUsedPassword()... yes
checking for PQisthreadsafe()... yes
checking for PQprepare()... yes
checking for PQexecParams()... yes
checking for PQescapeString()... yes
checking for PQescapeStringConn()... yes
checking for PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for pg_char_to_encoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for PQsetSingleRowMode()... yes
checking for PQconninfo()... yes
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... yes
checking for rb_thread_call_without_gvl()... yes
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_fd_select()... yes
checking for rb_w32_wrap_io_handle()... no
checking for rb_str_modify_expand()... yes
checking for rb_hash_dup()... yes
checking for PGRES_COPY_BOTH in libpq-fe.h... yes
checking for PGRES_SINGLE_TUPLE in libpq-fe.h... yes
checking for PG_DIAG_TABLE_NAME in libpq-fe.h... yes
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
checking for inttypes.h... yes
checking for ruby/st.h... yes
checking for C99 variable length arrays... yes
creating extconf.h
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/benwong/Desktop/ruby/rails_projects/blog2/vendor/bundle/ruby/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/pg-0.18.4/mkmf.log

current directory: /Users/benwong/Desktop/ruby/rails_projects/blog2/vendor/bundle/ruby/2.2.0/gems/pg-0.18.4/ext
make "DESTDIR=" clean

current directory: /Users/benwong/Desktop/ruby/rails_projects/blog2/vendor/bundle/ruby/2.2.0/gems/pg-0.18.4/ext
make "DESTDIR="
compiling gvl_wrappers.c
compiling pg.c
compiling pg_binary_decoder.c
compiling pg_binary_encoder.c
compiling pg_coder.c
compiling pg_connection.c
pg_connection.c:2394:3: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration]
                gettimeofday(&currtime, NULL);
                ^
1 warning generated.
compiling pg_copy_coder.c
compiling pg_errors.c
compiling pg_result.c
compiling pg_text_decoder.c
compiling pg_text_encoder.c
compiling pg_type_map.c
compiling pg_type_map_all_strings.c
compiling pg_type_map_by_class.c
compiling pg_type_map_by_column.c
compiling pg_type_map_by_mri_type.c
compiling pg_type_map_by_oid.c
compiling pg_type_map_in_ruby.c
compiling util.c
linking shared-object pg_ext.bundle
ld: warning: directory not found for option '-L/Users/haven/.sm/pkg/active/lib'
ld: file not found: dynamic_lookup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_ext.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/benwong/Desktop/ruby/rails_projects/blog2/vendor/bundle/ruby/2.2.0/gems/p

g-0.18.4 for inspection.
    Results logged to /Users/benwong/Desktop/ruby/rails_projects/blog2/vendor/bundle/ruby/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/pg-0.18.4/gem_make.out

Using puma 2.15.3
Using rails_serve_static_assets 0.0.4
Using rails_stdout_logging 0.0.4
Using sass 3.4.21
Using tilt 2.0.2
Using spring 1.6.2
Using rdoc 4.2.1
Using tzinfo 1.2.2
Using nokogiri 1.6.7.2
Using rack-test 0.6.3
Using warden 1.2.4
Using mail 2.6.3
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using uglifier 2.7.2
Using sprockets 3.5.2
An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.

最佳答案

您需要安装 PostgreSQL 才能安装 pg gem。还需要配置 PATH。 您可以使用 http://postgresapp.com/在 Mac 上轻松安装 PostgreSQL。并使用它来配置路径:http://postgresapp.com/documentation/cli-tools.html

关于ruby - Rails 错误运行 Gem 安装 PG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35006898/

相关文章:

ruby-on-rails - 在 Rails 中渲染 PNG 文件

sql - PostgreSQL : Add constraint with mulitple conditions

postgresql - 为什么 postgres 强制 sslmode=verify-full 虽然它不在连接字符串中

ruby-on-rails - 从Rails 2.3.8升级到4.0

Ruby ARGF 和额外参数不稳定

Ruby 和 if 语句

postgresql - typeorm:如何进行 RIGHT JOIN 和 SELECT

mysql - 为什么我的加入不起作用?

ruby - 如何将多个值推送到同一个哈希键

ruby - Prawn可以生成CMYK格式的PDF吗?