Bundle install a local pg gem without internet access - ruby-on-rails

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 --:
--local app/vendor/cached/pg.1.1.4.gem
--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

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

Related

Error installing nokogumbo gem with specific version

I am trying to do bundle install on my project.
Ruby: 2.5.1
Rails: 5.0.7.2
Bundler: 1.17.3
But when doing the bundle install, it gives me this error with the nokogumbo gem and it doesn't install it, I'm using a mac.enter image description here
Have you tried:
bundle config set force_ruby_platform true
bundle install
Otherwise, paste in your commands and the output so we can see a better view of what is going on.

I git cloned a repo and I cannot run it on localhost because missing gem and cannot bundle install

I git cloned a repo. I cannot run it on localhost with rails server because terminal says
Could not find activesupport-4.2.5 in any of the sources Run bundle
install to install missing gems.
When I run bundle install, I get
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.
I have rails 4.2.3, and the repo's Gemfile has gem 'rails', '4.2.5'. I don't know if this matter
Gem pg is Postgres driver, it only can be installed, if corresponding headers and libraries are present and can be accessed.
Most probably just installing postgres will fix it. If you're on a Mac with homebrew - brew install postgresql
Install postgresql.
Remove Gemfile.lock
Add gem 'pg' in your gemfile
execute bundle install
1: Remove Gemfile.lock if Gemgile.lock present in your project
2: add gem 'pg' # in Gemfile
3: Run bundle install
Hope this help you !!!
Run
sudo env ARCHFLAGS="-arch x86_64" gem install pg -v '1.18.4'
Now try running bundle install again.
I used a combination of #Chakreshwar Sharma and #Vinay's answers to get this working for the metasploit-framework.
Remove Gemfile.lock
Add gem 'pg' in your gemfile
Run apt-cache search postgresql-server-dev
apt-get update && apt-get install postgresql-server-dev-9.5 # Check your version
bundle install --no-deployment
To be honest, I think you could just run:
apt-cache search postgresql-server-dev
apt-cache search postgresql-server-dev-9.5
bundle install
...and you can avoid messing with the Gemfile, but I didn't get to verify it since mine started working after I made the adjustments.

Rails Bundler - specify with-opt-dir in Gemfile?

I am able to install puma after downloading openssl and executing the following command:
gem install -- --with-opt-dir=c:\openssl
The problem is then if I try to update puma with bundle, it knows nothing of this directory.
Can you specify -- --with-opt-dir= in a Rails Gemfile?
You can specify this in bundle config as follows: bundle config build.puma --with-opt-dir=your/opt/dir and bundler will pass it to the gem install.

Error after bundle install on production

Every time i install a gem on production using bundle install i got this error
Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound)
Also i get the following warning when i do a bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
I tried removing the Gemfile.lock and re-installed the gems but it still not working
Thanks in advance.

problem with bundle

I try command bundle install --local
but it show issue:
-bash: /usr/local/bin/bundle: /usr/local/bin/ruby: bad interpreter: No such file or directory.
please help me.
The solution that worked for me was entirely different, perhaps because I've been inconsistent about using RVM or not.
I used 'which bundler' to find out where bundler was being launched, it was from /usr/bin/bundler. Noticing that /usr/bin/bundler began with a location and version of ruby that did not exist on my system any more, I did
gem uninstall bundler
gem install bundler
Checking 'which bundler' again confirmed that bundler was now installed within a .rvm environment instead of /usr/bin/bundler, and now references the correct version of ruby; so bundle install now works for my rails project.
I think you need to export the path of ruby and bundle in your .bashrc (linux).
Open your .bashrc and add this line:
export PATH="$PATH:/usr/bin:/usr/local/bin/"
It should work.
The bundle executable is provided by the bundler gem. If you are using rvm then seeing which bundle in /usr/local/bin/bundle indicates a problem, because use of rvm means gems like bundler are installed under your home directory, usually in ~/.rvm/gems/....
# Symptoms of a broken bundler installation:-
# Cannot start Rails...
$ bin/rails s
/Users/rogermarlow/project/config/boot.rb:9:in 'rescue in <top (required)>': uninitialized constant Bundler (NameError)
# bundle not working...
$ bundle install
zsh: /usr/local/bin/bundle: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin: no such file or directory
# ^----- that path does not look right, rvm does not put gems there
$ which bundle
/usr/local/bin/bundle
# ^--- I want bundle from something under ~/.rvm/gems
# First check rvm is in effect:
$ rvm reload
RVM reloaded!
$ which ruby
/Users/rogermarlow/.rvm/rubies/ruby-2.3.4/bin/ruby
# ^--looks good, it is an rvm path, not /usr/local/bin/...
# Now fix bundler
$ gem uninstall bundler # just in case
$ gem install bundler
Fetching: bundler-1.16.1.gem (100%)
Successfully installed bundler-1.16.1
1 gem installed
$ which bundle
/Users/rogermarlow/.rvm/gems/ruby-2.3.4#project/bin/bundle
$ ^--- that is better, bundle is on a path controlled by rvm
# bundle now working
$ bundle install
Fetching gem metadata from http://rubygems.org/..........
*snip*
# rails now working
$ bin/rails s
=> Booting Thin
=> Rails 4.2.7.1 application starting in development on http://localhost:3000
*snip*
On my side, I am using rbenv.
When I checked the /usr/local/bin/bundle, it shows it is using the older ruby, thus causing the problem.
#!/usr/bin/ruby1.9.1
by changing it to point to proper ruby fix the problem
#!/home/user/.rbenv/shims/ruby
For newly created gem-set gem bundler is missing for me,
Before bundler install path for it, /usr/local/bin/bundler
Installed bundler to resolve issue.
gem install bundler --no-ri --no-rdoc
Bundler path changes to, /home/root/.rvm/gems/ruby-2.2.1#drag-drop-list/bin/bundler
Encountering this same problem,
I found bundler installation in /var/lib/gems/2.3.0/gems/bundler-1.16.1;
Then i fixed the error by creating a symbolic link like this:
ln -s /var/lib/gems/2.3.0/gems/bundler-1.16.1/
/usr/lib/ruby/gems/2.3.0/gems/bundler-1.16.1
I did this because I needed this version of ruby.

Resources