尝试升级到 rails 5:确保 `gem install pg -v '0.18.4'` 在捆绑前成功

Trying to upgrade to rails 5: Make sure that `gem install pg -v '0.18.4'` succeeds before bundling

我正在尝试更新到 Rails 5. 我已成功将我的 gem 文件中的 Ruby 更新为“2.3.1”,并且 运行 捆绑安装.

然后我去了 Rails 5.0,它告诉我:

Make sure that gem install pg -v '0.18.2' succeeds before bundling.

我把 rails 放回 4.2,就像现在一样,我尝试通过 运行 gem install pg -v '0.18.2' 在终端中更新 pg,并通过更新 gem文件和 运行 bundle install 并且两次都出现此错误:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /Users/w*****n/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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=/Users/w******n/.rvm/rubies/ruby-2.1.2/bin/ruby
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

extconf failed, exit code 1

Gem files will remain installed in /Users/w******n/.rvm/gems/ruby-2.1.2/gems/pg-0.18.2 for inspection.
Results logged to /Users/w*******n/.rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/pg-0.18.2/gem_make.out

我发现 这是一个类似的错误,但是当我尝试他们的解决方案时,它不起作用。

我的问题有 1.5 个部分: 1.如何让pg升级到最新版本 .5 为什么我会收到这个错误,我该如何解释该错误?

更新:

重新安装 pg 并收到:

==> Pouring postgresql-9.6.1.yosemite.bottle.tar.gz
==> /usr/local/Cellar/postgresql/9.6.1/bin/initdb /usr/local/var/postgres
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/2510

To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see:
  https://www.postgresql.org/docs/9.6/static/upgrading.html

To migrate existing data from a previous minor version (9.0-9.5) of PostgreSQL, see:
  https://www.postgresql.org/docs/9.6/static/pgupgrade.html

  You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`.
  Do not run `brew cleanup postgresql` until you have performed the migration.

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
==> Summary
  /usr/local/Cellar/postgresql/9.6.1: 3,242 files, 36.5M

运行 psql -V : psql (PostgreSQL) 9.6.1

现在重新安装 pg 并尝试 bundle update rails 后,我收到此错误:

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

    current directory: /Users/w*******n/.rvm/gems/ruby-2.3.1/gems/pg-0.18.2/ext
/Users/w******n/.rvm/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20170103-82113-1miw542.rb extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/Versions/0.18.2/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/Versions/0.18.2/bin/pg_config
sh: /Applications/Postgres.app/Contents/Versions/0.18.2/bin/pg_config: No such file or directory
sh: /Applications/Postgres.app/Contents/Versions/0.18.2/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()... no
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 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/w******n/.rvm/gems/ruby-2.3.1/extensions/x86_64-darwin-14/2.3.0/pg-0.18.2/mkmf.log

current directory: /Users/w*******n/.rvm/gems/ruby-2.3.1/gems/pg-0.18.2/ext
make "DESTDIR=" clean

current directory: /Users/w*******n/.rvm/gems/ruby-2.3.1/gems/pg-0.18.2/ext
make "DESTDIR="
compiling gvl_wrappers.c
compiling pg.c
compiling pg_binary_decoder.c
compiling pg_binary_encoder.c
compiling pg_coder.c
pg_coder.c:188:34: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
              ~~~~                      ^~~~~~~~~~~~~~~~~~~~
/Users/w*******n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:998:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/w********n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:994:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg_coder.c:188:34: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
              ~~~~                      ^~~~~~~~~~~~~~~~~~~~
/Users/w******n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:999:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
pg_coder.c:188:56: warning: implicit conversion loses integer precision: 'VALUE' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
        res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
              ~~~~                                            ^~~~~
pg_coder.c:188:63: warning: implicit conversion loses integer precision: 'VALUE' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
        res = this->dec_func(this, val, RSTRING_LEN(argv[0]), tuple, field, ENCODING_GET(argv[0]));
              ~~~~                                                   ^~~~~
4 warnings generated.
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
pg_copy_coder.c:218:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                                        strlen = RSTRING_LEN(subint);
                                               ~ ^~~~~~~~~~~~~~~~~~~
/Users/w*******n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:998:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/w******n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:994:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg_copy_coder.c:218:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                                        strlen = RSTRING_LEN(subint);
                                               ~ ^~~~~~~~~~~~~~~~~~~
/Users/w*******n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:999:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
pg_copy_coder.c:501:23: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                input_len = end_ptr - start_ptr;
                          ~ ~~~~~~~~^~~~~~~~~~~
3 warnings generated.
compiling pg_errors.c
compiling pg_result.c
compiling pg_text_decoder.c
compiling pg_text_encoder.c
pg_text_encoder.c:162:14: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                        len = out - start;
                            ~ ~~~~^~~~~~~
pg_text_encoder.c:281:15: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                return optr - out;
                ~~~~~~ ~~~~~^~~~~
pg_text_encoder.c:285:12: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
                return 2 + RSTRING_LEN(*intermediate) * 2;
                ~~~~~~ ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg_text_encoder.c:491:13: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        nr_elems = RARRAY_LEN(value);
                 ~ ^~~~~~~~~~~~~~~~~
/Users/w********n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:1044:23: note: expanded from macro 'RARRAY_LEN'
#define RARRAY_LEN(a) rb_array_len(a)
                      ^~~~~~~~~~~~~~~
4 warnings generated.
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
pg_type_map_by_column.c:161:52: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        return dec_func( p_coder, RSTRING_PTR(field_str), RSTRING_LEN(field_str), 0, fieldno, enc_idx );
               ~~~~~~~~                                   ^~~~~~~~~~~~~~~~~~~~~~
/Users/w********n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:998:6: note: expanded from macro 'RSTRING_LEN'
     RSTRING_EMBED_LEN(str) : \
     ^~~~~~~~~~~~~~~~~~~~~~
/Users/w********n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:994:6: note: expanded from macro 'RSTRING_EMBED_LEN'
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pg_type_map_by_column.c:161:52: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        return dec_func( p_coder, RSTRING_PTR(field_str), RSTRING_LEN(field_str), 0, fieldno, enc_idx );
               ~~~~~~~~                                   ^~~~~~~~~~~~~~~~~~~~~~
/Users/w*********n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:999:28: note: expanded from macro 'RSTRING_LEN'
     RSTRING(str)->as.heap.len)
     ~~~~~~~~~~~~~~~~~~~~~~^~~
pg_type_map_by_column.c:230:17: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        conv_ary_len = RARRAY_LEN(conv_ary);
                     ~ ^~~~~~~~~~~~~~~~~~~~
/Users/w********n/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/ruby.h:1044:23: note: expanded from macro 'RARRAY_LEN'
#define RARRAY_LEN(a) rb_array_len(a)
                      ^~~~~~~~~~~~~~~
3 warnings generated.
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
util.c:119:24: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        return (char*)out_ptr - out;
        ~~~~~~ ~~~~~~~~~~~~~~~^~~~~
1 warning generated.
linking shared-object pg_ext.bundle
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/w********n/.rvm/gems/ruby-2.3.1/gems/pg-0.18.2 for inspection.
Results logged to /Users/w*******n/.rvm/gems/ruby-2.3.1/extensions/x86_64-darwin-14/2.3.0/pg-0.18.2/gem_make.out

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

我没有我正在寻找的完整答案,但在有人可以解释发生了什么之前,这是我安装 Rails 5 所做的:

我卸载并重新安装了 pg。

然后 运行 bundle update rails 并收到上面发布的最后一个错误日志。

为了解决这个问题,我 运行 sudo gem install rails

然后我收到这个错误:Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and rungem pristine --allfor better startup performance. 并由 运行ning gem update --system

解决

现在我可以成功 运行 gem install pg -v '0.18.2' 并最终克服了最初的错误,在我上面发布的第一个日志中。

还没有结束...尝试启动 rails 服务器,并收到此错误:

Array values in the parameter toGem.paths=are deprecated. Please use a String or nil. Sorry, you can't use byebug without Readline. To solve this, you need to rebuild Ruby with Readline support. If using Ubuntu, trysudo apt-get 安装 libreadline-devand then reinstall your Ruby. 我拿出了byebuggem,只好又运行gem install pg -v '0.18.2',然后bundle update 所有这一切之后,rails 终于更新了(已经在我的 gem 文件中声明了 5.0)并且服务器将启动。服务器启动时有警告:

Array values in the parameter toGem.paths=are deprecated. Please use a String or nil. An Array ({"GEM_PATH"=>["/Users/walshcostigan/.rvm/gems/ruby-2.3.1", "/Users/walshcostigan/.rvm/gems/ruby-2.3.1@global"]}) was passed in from bin/rails:3:in加载' `

但它是 Rails 5,它是 运行ning,所以现在这就是我解决这个问题的方法。希望这对其他人有帮助,任何对此问题的见解都将受到赞赏!