ruby - bundle install/update too slow - ruby-on-rails

I just installed RVM, Ruby, Rails etc. on my virtual ubuntu 12.04 32bit running in a virtualbox. Now I encounter the problem that for my first rails project bundle install or bundle update takes very long time. Even when I create a new project with rails (which includes bundle install).
I use only the standard gems:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
gem 'sqlite3', '1.3.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
I tried bundle install without any gems but gem 'rails', '3.2.12'. After that I typed again bundle install with all gems in my gemfile. It took me 10 minutes to check for dependencies. The output of --verbose is a mix of HTTP success and HTTP redirection.
Rails version: Rails 3.2.12
Ruby version: ruby 1.9.3p392 (2013-02-22 revision 39386)
Rvm: rvm 1.18.18
bundle version: Bundler version 1.3.2
I already searched fot a solution, but nothing helped.

I want to warn: There is a security purpose for using https over http. Try at first the other answers mentioned in this thread.
Changing https to http in my Gemfile did the magic. Before I have to create the project with rails new APP --skip-bundle

Bundler just got an update of parallel processing of gems.
gem install bundler --pre
will solve the problem in the best possible way for now.
Source

You can also use multiple jobs, it may improve a little bit
bundle install --jobs 8
Here is a tutorial about it

Bundler v1.12.x was released in 2016 and caused some users to experience slow bundle install issues.
In this instance staying with v1.11.2 is the best option (it's fast) until a fix is released.
It's worth heading over to Rubygems.org to try different versions of the bundler gem.
Check existing bundler versions, uninstall existing version, install version 1.11.2 example:
gem list | grep bundler
gem uninstall bundler -v existing-version-number
gem install bundler -v 1.11.2

A developer friendly method is to override the gem server with a faster alternative.
In our case, we can configure http as a mirror to address slow https connections:
bundle config mirror.https://rubygems.org http://rubygems.org
This allows you to keep original Gemfile configuration while still using faster http connections to fetch gems.
If you wanted to switch back to https:
bundle config --delete mirror.https://rubygems.org
bundle config has a default --global option. You can specify --local to limit configurations to local application folder.
Configuration is saved into global ~/.bundle/config and local .bundle/config.

If you're still seeing this issue with Bundler 1.12.5, you may want to try updating the OpenSSL used by your Ruby.
For me this went like so:
pmorse$ bundle --version
Bundler version 1.12.5
pmorse$ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 1.0.1j 15 Oct 2014
pmorse$ openssl version
OpenSSL 0.9.8zg 14 July 2015
pmorse$ brew info openssl
openssl: stable 1.0.2h (bottled) [keg-only]
[... more brew output ...]
pmorse$ rvm reinstall ruby-2.2.2 --with-openssl-dir=`brew --prefix openssl`
[... lots of rvm output ...]
pmorse$ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 1.0.2h 3 May 2016
This should make bundle quicker again without requiring you to go from https to http.

I know this may be basic answer but try to install developer tools from the main Ruby site. I have had a similar problem and it did work. Sometimes simple solutions are the best!
Good luck!

Related

Is there a way to get a gem's version before running bundle install (from Gemfile.lock)

I want to get a Gem's version without running bundle install.
Which is to say I want figure out what version bundle is planning to install without actually installing the gem.
Say read it from the Gemfile.lock(and Gemfile) combined.
Is there a way I can resolve what version bundler plans to install?
I need this because I want to cache the expensive installs while running docker build.
Gems like rails(nokogiri) take a while to install and I would like to do gem install rails -v ... in a previous step before running bundle install.
For this purpose i need to get the rails version before hand
If you add a new gem to your gemfile, but don't do bundle install, it doesn't install yet. Instead, you can run bundle lock, which generates a new lock file. This includes the gem version of the new gem that would be installed.
By running bundle show new_gem, it shows it isn't actually installed.
To be sure maybe get a backup of the original Gemfile.lock before running the command though.
By default if no version is specified in the Gemfile, running bundle install will attempt to install the latest version of the gem which is compatible with the rest of the gems and ruby version in your project. This will create a Gemfile.lock file if one doesn't already exist. If a Gemfile.lock file is already committed to git repo, it should then install the versions specified in Gemfile.lock. The point of bundler is to handle dependencies to insure your stack works correctly.
To see the version of a gem bundler is currently using you can run
bundle show rails
You will probably want to specify the ruby version in the Gemfile for example
ruby '~> 2.5' #
You can specify exact version of a gem in the Gemfile like this which you should be able to rely on to be the version bundler will install so long as it's compatible with the rest of the stack. bundle install will throw errors if there are incompatible gem versions.
gem 'rails', '4.2.11' # this will always install only this version.
You may also use pessimistic operator (~>) to set for only minor updates
gem 'influxdb', '~> 0.6.1' # could go to 0.6.2 but never 0.7.0
You can also set minimum versions like this although it's probably not what you need for your question.
gem 'pg_query', '>= 0.9.0'
If you have a Gemfile.lock already in your repo you can see which version would be installed by running for example:
gem show rails
Which would show you the version and weather it or not it is currently installed.
For more info see bundle --help

Specifying JRuby Version in Bundler

I wasn't able to find a SO QA that could answer this.
I installed JRuby via rvm install jruby and then generated a new rails application. To allow for changing of the ruby version automatically via rvm, I discovered that Bundler allows you to add:
ruby '1.9.3', engine: 'jruby', engine_version: '1.7.12'
See here for reference. Since this is 1.3, I checked my Bundler version within my root app directory:
$ bundle -v
Bundler version 1.6.2
I'm assuming I have this functionality. Now, when I move onto adding this to Gemfile:
source 'https://rubygems.org'
ruby '1.9.3', engine: 'jruby', engine_version: '1.7.12'
gem 'rails', '4.1.1'
gem 'activerecord-jdbcsqlite3-adapter'
And then after running cd .. && cd app I received this issue:
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /Users/benmorgan/Sites/sigma/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.
Unknown ruby string (do not know how to handle): ruby-1.9.3,engine:jruby,engine_version:1.7.12.
Do you know how to tell rvm to select the jruby version? Is it possible within the Gemfile?
as suggested by the comment already linking to RVM reports Gemfile ruby as not installed
RVM's support for resolving a Ruby "engine" from the Gemfile is limited and does not match how Heroku is using (parsing) the directive.
if you really want to have it both in the Gemfile use a comment for RVM e.g.
source "https://rubygems.org"
#ruby=jruby-1.7.12
if ENV["JRUBY"] || RUBY_PLATFORM == "java"
ruby "1.9.3", engine: "jruby", engine_version: "1.7.12"
end
gem "rails", "~> 4.1.1"
# ...

Bundler cannot find a version of a gem, but gem install with the same name works

I've created a gem, and for some reason this one keeps bugging me, and refuses to install properly through bundler.
Here's the Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.9'
gem "switch_access-rails", "~> 1.1.6"
bundle install fails with:
Could not find gem 'switch_access-rails (~> 1.1.6) ruby' in the gems available on this machine.
This works:
gem install switch_access-rails -v 1.1.6
And the gem is here on rubygems: https://rubygems.org/gems/switch_access-rails/versions/1.1.6
I even tried bumping from version 1.1.5 to 1.1.6 just to see if that helped.
Installing version 1.1.4 in with bundle install works.
Any tips on where to start looking/debugging bundle install?
And after a whole day of googling I found this status update from Dec 12: http://twitter.com/rubygems_status/status/279019743166476288
bundle install --full-index
Seems to get the index directly from rubygems instead of from a cloudfront cache.
I had a look at the index, and there is quite a diffence in the two indexes, so if you just released a gem or use a newly released gem, you might have to add --full-index in order to get the proper index.
Do you have rubygems listed as a remote source?
Your Gemfile should have source :rubygems at the top of the file, and $ gem sources should return at a minimum:
*** CURRENT SOURCES ***
http://rubygems.org/
If it's not listed, you can add it with $ gem sources -a http://rubygems.org

Avoid "bundle install" to use pre-compiled gems

This is my very first question here :)
On a rails 3.2.6 (using rvm and ruby 1.8.7), my Gemfile contains two gems that cause problems when using the bundle install command.
Those gems are specified using:
gem 'libv8', "~> 3.11.8.3"
gem 'therubyracer', '~> 0.11.0beta6'
My problem is the following: when running bundle install command, bundler fetches binaries (precompiled) gems (libv8-3.11.8.3-x86_64-linux.gem and therubyracer-0.11.0beta6-x86_64-linux.gem) and not the plain source ones (libv8-3.11.8.3.gem and therubyracer-0.11.0beta6.gem).
The x86_64 version is incompatible with my server setup: included dynamic library uses an unknown symbol (rb_intern2, out of my old memory, I could be wrong) that makes that the precompiled gems cant be loaded by the application.
So that I must install gem from the source packages.
At the moment, I have to bundle install, then remove the precompiled gems from my ~/.rvm/gems/... and then gem install ~/tmp/libv8-3.11.8.3.gem and gem install ~/tmp/therubyracer-0.11.0beta6.gem, which is not very practical.
Is there any way to force Bundler to fetch the sources release and compile them ?
try:
bundle install --without x86_64-linux
x86_64-linux is a platform and bundler/rubygems uses it.
It should be equivalent of:
gem install libv8 -​-platform ruby
Details:
http://gembundler.com/man/gemfile.5.html
http://guides.rubygems.org/command-reference/#gem_install

Bundler could not find compatible versions for gem "bundler":

Complete new person to Ruby and Rails here... Have tried some tutorials in the past, but that's about it. I'm trying to follow 'Ruby on Rails 3 Tutorial' book and have hit a roadblock that I haven't been able to find any help for after searching on here and the Google..
I haven't actually done anything yet; only:
rails new first_app
then changed the Gemfile sqlite3 to
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
When I run 'bundle install' I get the following:
Fetching gem metadata from http://rubygems.org/.........
Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (= 3.0.1) ruby depends on
bundler (~> 1.0.0) ruby
Current Bundler version:
bundler (1.1.3)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running `gem install bundler`?
I've tried uninstalling the bundler via
gem uninstall bundler -v 1.1.3
and then installing bundler v1.0.0 via
gem install bundler -v 1.0.0
but it seems to get me bundler 1.1.2..
I just feel like I've hit a dead end and can't find any more information on how to solve this issue.
Any help would be greatly appreciated and rewarded with copious amounts of bacon...
UPDATE UPDATE UPDATE
I couldn't get bundler v 1.1.2 to uninstall. I finally was able to uninstall all of the gems by doing:
sudo gem list | cut -d" " -f1 > gem_list.txt
cat gem_list.txt | xargs sudo gem uninstall -aIx
cat gem_list.txt | xargs sudo gem install
And then reinstalling... This allowed me to then do the 'bundle install' and get on track.. Thank you all for your help!
it is because gems are also installed in global gemset, and you can uninstall it using:
rvm #global do gem uninstall bundler
but you can also use the other version of bundler using:
gem install bundler -v '~>1.0.0'
bundle _1.0.0_ install
replace 1.0.0 with the version that got installed (if other)
First verify your versions to be sure they're all current:
$ ruby -v
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
$ rails -v
Rails 3.2.2
$ gem list bundler
*** LOCAL GEMS ***
bundler (1.1.3)
If you need to update ruby, you can download it from https://www.ruby-lang.org or use tools like ruby-build. If you have any version of Ruby 1.9.3 that's fine for now.
To update all your gems:
gem update --system
gem update
Gem may install gems in a few different places, and these can interfere with each other. There are system gems (typically installed by root or by using sudo) and your personal user gems. My favorite way to manage these is with a simple tool called rbenv. A related tool is rvm. Either is fine.
For your first tutorial, you can skip using version numbers in your Gemfile:
- gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
+ gem 'sqlite3-ruby', :require => 'sqlite3'
Bundler will sort everything out the right way. Eventually you'll want to specify version numbers if you're coordinating with other developers, or building production systems.
Feel free to ask questions here and I'll add to this answer.
Maybe you had bundler 1.1.2 AND 1.1.3 installed on your machine (and possibly more versions)
use
gem list bundler
to check which version(s) of bundler you have installed.
Then remove the ones you don't want with
gem uninstall bundler -v VERSION_NUMBER
You can use latest version of Rails 3.0 (3.0.12). It supports the latest bundler, and isn't fundamentally different from 3.0.1
I had this problem and the source was a version specification for bundler in the .gemspec file:
spec.add_development_dependency "bundler", "~> 1.16"
Removing the version number solved the issue:
spec.add_development_dependency "bundler"
Bundler is a dependent gem of rails, because of which you can see it only in gemfile.lock instead of gemfile.
For a particular rails version only a range of bundler gems are compatible. I also got this error and I tried uninstalling that version of bundler gem which I didn't need. I also tried to install forcefully using bundle_x.x.x_install, but when things didn't work I explicitly mentioned the gem specifying the version falling within the range required by rails version I am using. May be it's not the right way but that is how things worked for me.
Sometimes to fix the issue mentioned in the title of this question it is enough to delete Gemfile.lock and run bundle update. I hope it will be helpful for someone.

Resources