Ruby 运行Gem安装程序时发生Rails错误

Ruby 运行Gem安装程序时发生Rails错误,ruby,postgresql,ruby-on-rails-4,rubygems,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安装时,我在控制台中遇到以下错误: An error occurred while installing pg (0.18.4), and Bundler cannot continue. Make sure that `

我正在尝试将我的应用程序推送到Heroku,我将我的gemfile配置为:

group :production do
  gem 'pg', '0.18.4'
  gem 'rails_12factor', '0.0.2'
  gem 'puma'
end
在运行bundle安装时,我在控制台中遇到以下错误:

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.
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.
当我运行
sudogem安装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.
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安装时,我得到了以下信息:

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。此外,还需要配置路径。
您可以使用在Mac上轻松安装PostgreSQL。并使用此配置路径:

您需要安装PostgreSQL才能安装pg gem。此外,还需要配置路径。
您可以使用在Mac上轻松安装PostgreSQL。并使用此配置路径:

很多时候,您可以在安装gems时找到类似的答案,因为internet速度很慢。。。你确定不是吗?你又试过了吗?你的第二个片段就是线索。。。解释其余部分。

很多时候,你可以在安装gems时找到类似的答案,只是因为互联网速度太慢。。。你确定不是吗?你又试过了吗?你的第二个片段就是线索。。。解释其余部分。

试试这个,它对我有效,它必须具有所有的psql依赖性,才能工作

sudo apt-get install -y libpq-dev build-essential postgresql-server-dev-all libpgsql-ruby postgresql ruby-dev && gem install pg

试试这个,它对我有用,它必须有所有的psql依赖,这样它才能工作

sudo apt-get install -y libpq-dev build-essential postgresql-server-dev-all libpgsql-ruby postgresql ruby-dev && gem install pg

作为普通用户和root用户运行时是否使用相同的pg_配置?抱歉。我不明白。我用pg config再次尝试了sudogem安装,结果是:错误:在执行gem时。。。(Gem::FilePermissionError)您没有/Library/Ruby/Gems/2.0.0目录的写入权限。作为普通用户和root用户运行时是否使用相同的pg_配置?抱歉。我不明白。我用pg config再次尝试了sudogem安装,结果是:错误:在执行gem时。。。(Gem::FilePermissionError)您没有/Library/Ruby/Gems/2.0.0目录的写入权限。我安装了PostgreSQL并配置了路径,但仍然提供:(安装pg(0.18.4)时出错,绑定程序无法继续。请确保
Gem install pg-v'0.18.4'
在绑定之前成功)当我进行捆绑安装时。我安装了PostgreSQL并配置了路径,但在进行捆绑安装时,仍然会给出:(安装pg(0.18.4)时出错,捆绑程序无法继续。请确保
gem install pg-v'0.18.4'
在捆绑前成功)。