Search code examples
ruby-on-railsrubybundlepg

Bundle install a local pg gem without internet access


I'm on a remote server with no internet access. Have a Rails app. Trying to bundle install (All gems were cached using bundle package --all to app/vendor/cached)

Since no internet connection I'm using the --local flag (Tells bundle to use cached values- link): Running bundle install --local fails saying:

An error occurred while installing pg (1.1.4), and Bundler cannot continue.
Make sure that "gem install pg -v '1.1.4' --source 'https://rubygems.org'" succeeds before bundling.

Now the cached gem is at app folder at app/vendor/cached/pg.1.1.4.gem It only happen with the pg gem.

Usually I solve this problem using: bundle config build.pg --with-pg-include=/usr/pgsql-10/include --with-pg-dir=/usr/pgsql-10 (Which basically tells bundle to use those arguments when installing pg). But that's when I have internet connection.

Now I can install pg manually using this command: gem install --local app/vendor/cached/pg.1.1.4.gem -- --with-pg-include=/usr/pgsql-10/include --with-pg-dir=/usr/pgsql-10 Notice there are two parts for the arguments, separated by --:

  1. --local app/vendor/cached/pg.1.1.4.gem
  2. --with-pg-include=/usr/pgsql-10/include --with-pg-dir=/usr/pgsql-10

So the first part of the arguments: --local app/vendor/cached/pg.1.1.4.gem

How do I get bundle to do it? At my workstation where I have internet connection I still got that error but use this to fix it: bundle config build.pg --with-pg-include=/usr/pgsql-10/include --with-pg-dir=/usr/pgsql-10 Which basically tells bundle to use those arguments when installing pg

But now additionally bundle need also to use a local path? I guess? (like the gem install command uses? It tries to connect to rubygems.org

To summarize: how to make bundle install install a local pg gem? or convert the previously shown working gem install command to bundle install command?

ruby 2.5.3, rails 5.2.1, bundler 1.17.3

output for bundle config:

build.pg (/home/myuser/.bundle/config): "--with-pg-include=/usr/pgsql-10/include --with-pg-dir=/usr/pgsql-10"

I tried several combinations using the bundle config build.pg command but no success:

  • bundle config build.pg --with-pg-include=/usr/pgsql-10/include --with-pg-dir=/usr/pgsql-10
  • bundle config build.pg --local app/vendor/cached/pg.1.1.4.gem -- --with-pg-include=/usr/pgsql-10/include --with-pg-dir=/usr/pgsql-10

Solution

  • Solved it by running bundle config build.pg --with-pg-config=/usr/pgsql-10/bin/pg_config.