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

1.1k views Asked by At

I am trying to update to Rails 5. I have successfully updated Ruby to '2.3.1' in my gem file, and ran bundle install.

Then I went for Rails 5.0, and it told me:

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

I put rails back to 4.2 like it is now, and I tried to update pg in the terminal by running gem install pg -v '0.18.2', and by updating the gem file and running bundle install and both times get this error:

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

Ive found this post which is a similar error, but when I try their solutions, it does not work.

My question has 1.5 parts: 1. How can I get pg to upgrade to the newest version .5 Why am I getting this, and how do I interpret that error?

UPDATE:

reinstalled pg and received this:

==> 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

running psql -V : psql (PostgreSQL) 9.6.1

Now after reinstalling pg, and trying to bundle update rails, I get this error:

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.
1

There are 1 answers

0
gwalshington On BEST ANSWER

I don't have the full answer I'm looking for, but until someone can explain what happened, here is what I did to get Rails 5 installed:

I uninstalled and reinstalled pg.

Then ran bundle update rails and received the last error log posted above.

To get over that issue, I ran sudo gem install rails

Then I was getting this error: 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. and solved by running gem update --system

Now I could successfully run gem install pg -v '0.18.2' and finally get past the original error, in the first logs I posted above.

It's not over... try spinning up the rails server, and get this error:

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 install libreadline-devand then reinstall your Ruby. I took out byebug gem, had to run gem install pg -v '0.18.2' again, then bundle update After all of this, rails is finally updated (having already declared 5.0 in my gem file) and the server will start. There are warnings when the server starts:

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:inload' `

But it is Rails 5, and it is running, so for now that is how I solved this. Hopefully this helps someone else, and any insight into the issue is appreciated!