Can't force gems to a specific version in Rails 3 application - ruby-on-rails-3

After a bundle update, I want to rollback some gem versions to a specific one. I've tried several options, but I can't do it.
Say I want to use arel in its 2.0.9 version. I did the following:
sudo gem uninstall arel -v 2.0.10
Then in the Gemfile:
gem 'arel', '~> 2.0.9'
And then:
bundle update
Then I get:
Installing arel (2.0.10)
I also tried with gem cleanup and deleting Gemfile.lock, but no.. I allways get the same arel 2.0.10 installed. Am I missing something? Thank you very much!

You're telling it to install any patch version greater than or equal to 2.0.9. If you want to specifically install that version just do this:
gem 'arel', '2.0.9'

Related

Can't remove gem

Have a very strange problem. I have RVM and rails project. I used 'breadcrumbs_on_rails' gem and I had it in my Gemfile. After one update I got some errors in this gem, so I tried to roll back to previous version. I wrote version in Gemfile, ran bundle update - but nothing changed, there were still errors. I tried totally remove this gem from Gemfile, but... it's helpers were still working! I uninstalled gem completely, all versions, by running gem uninstall, cleared tmp folder of project, rebooted, but it is still working. What can be the reason?
Have you tried using
bundle exec gem uninstall GEM_NAME
For RVM users:
you have to use this method if you've set up a gemset for your particular project.
Running gem uninstall GEM_NAME from the project folder will uninstall GEM_NAME from your global/system level gemset instead of bundler's.
Problem was in conflict of two gems
gem twitter-bootstrap-rails have exactly same methods - add_breadcrumb and render_breadcrumbs. And breadcrumbs were rendered by this gem, not by breadcrumbs_on_rails.
So, it turns out, that gem was removed successfully

How does bundler know which version of a gem to install?

I have been using the less-rails-bootstrap gem from https://github.com/metaskills/less-rails-bootstrap in my rails 3.1 project.
I want to upgrade to the 2.0wip version of bootstrap and I found a fork with the same name under https://github.com/sgruhier/less-rails-bootstrap
Both version say to install you add gem 'less-rails-bootstrap' to your gemfile.
Well, how is bundler going to know which one to use? What if 20 people had gems with the exact same name?
I guess the bigger question is how to I specify which gem to use?
Bundler will use the one found on http://rubygems.org, which is the one at the first link you posted.
When trying to use an unreleased branch/fork, you should pass the :git option in your Gemfile to tell Bundler to use that git repository:
gem 'less-rails-bootstrap', :git => "git://github.com/sgruhier/less-rails-bootstrap.git"

ruby_threadptr_data_type error

I'm starting up a new rails app with the latest version of rails (3.1.3). Rails crashes when I try to start up the server. First I fixed this bug, and now I'm getting this one
ruby-debug-base19-0.11.25/lib/ruby_debug.so: undefined symbol: ruby_threadptr_data_type
There's a discussion about this going on here, but I can't make enough sense of it to get things to work.
UPDATE
I updated the version of ruby-debug
gem 'ruby-debug-base19x', '~> 0.11.30.pre4'
and have now moved on to this error
linecache19-0.5.12/lib/trace_nums19.so: undefined symbol: ruby_current_thread
Ok, it turns out that both ruby-debug and linecache needed to be manually updated to the latest versions. These lines in my gemfile did the trick
gem 'linecache19', :git => 'git://github.com/mark-moseley/linecache'
gem 'ruby-debug-base19x', '~> 0.11.30.pre4'
gem 'ruby-debug19'
To run specs, you need to run bundle exec rspec -d spec
At last I found the problem. The debugger in RubyMine starts without bundle exec, so it doesn't use linecache19 from git. You need to install it manually.
Resolution of the problem found here: http://youtrack.jetbrains.com/issue/RUBY-9418?projectKey=RUBY
gem uninstall linecache19
gem uninstall ruby-debug-base19x
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
gem install linecache19-0.5.13.gem
gem install ruby-debug-base19x –-pre
Make sure to uninstall all linecache19 and ruby-debug-base19x!
The following lines worked for me:
gem 'linecache19'
gem 'ruby-debug-base19x'
gem 'ruby-debug19', :require => 'ruby-debug'
(Hat tip to declan. His comment didn't work for me, but it gave me the idea to add linecache19.)
after trying all advise on stackoverflow, the following combination worked for me
gem 'linecache19', :git => 'git://github.com/mark-moseley/linecache'
gem 'ruby-debug-base19x', '~> 0.11.30.pre4'
gem 'ruby-debug19'
I'm running Rails 3.1.3 on Ruby 1.9.3-p0 with RVM
when I set :require => 'ruby-debug' the server would not start.
It's repost from this
I also ran into this, and found the solution in Ruby 1.9.3 and ruby-debug. You need to install not-yet-officially-released versions of ruby-debug-base19 and linecache19. The currently released versions indeed cause the exception you had.
Use this gist.
#To install ruby-debug on Ubuntu ruby-1.9.3 you need to download from http://rubyforge.org/frs/?group_id=8883
linecache19-0.5.13.gem
ruby_core_source-0.1.5.gem
ruby-debug19-0.11.6.gem
ruby-debug-base19-0.11.26.gem
#Then in your console
export RVM_SRC=/your/path/to/ruby-1.9.3
# Note, your source path should be something like /home/user/.rvm/src/ruby-1.9.3-p0
gem install archive-tar-minitar
gem install ruby_core_source-0.1.5.gem -- --with-ruby-include=/$RVM_SRC
gem install linecache19-0.5.13.gem -- --with-ruby-include=/$RVM_SRC
gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=/$RVM_SRC
gem install ruby-debug19-0.11.6.gem -- --with-ruby-include=/$RVM_SRC
I tried it and it's work!
This is solve of our problems.

jruby, glassfish gem and bundler

I wonder if anybody has the following issue:
in a jruby environment, I can do:
gem install glassfish
no problem
But if I add
gem 'glassfish'
to my Gemfile and do
bundle install
it always complain glass fish gem cannot be found.
Any solution to this? Thanks
Do you have source "http://rubygems.org" in your Gemfile? I just tested
source "http://rubygems.org"
gem 'glassfish'
and it was fine:
$ cat > Gemfile
source 'http://rubygems.org'
gem "glassfish"
$ jruby -S bundle install
Fetching source index for http://rubygems.org/
Using rack (1.3.5)
Installing glassfish (1.0.3)
Using bundler (1.0.21)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Having said that, please keep in mind that glassfish gem is not maintained at this time. For the alternatives, please check this blog post: http://www.engineyard.com/blog/2011/taking-stock-jruby-web-servers/
It turned out to be something wrong with the Gemfile.lock. deleted the file and reinstall fixed the issue.

Bundler could not find compatible versions for gem

I've added a gem 'koala' to my Gemfile and seems to have thrown gem versions out of whack when I run the 'bundle install' command:
Bundler could not find compatible versions for gem "faraday":
In snapshot (Gemfile.lock):
faraday (0.6.1)
In Gemfile:
koala (~> 1.2.0beta1) depends on
faraday (~> 0.7.4)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
How can I resolve this conflict?
Delete the contents of Gemfile.lock, and run bundle install again. That's been working for me.
Did you run bundle update as the error message points out? bundle install handles changes to the Gemfile and bundle update upgrades gems that are already managed by Bundler. The Gemfile.lock file locks in version numbers, bundle update will update any of those that aren't directly specified in your Gemfile (like gem 'rails', '3.0.9').
Deleting the Gemfile.lock will work, but running bundle update is better.
You can't simply delete you Gemfile.lock if that is a solution then why Gemfile.lock is exist in the first place, you code depend on the versions locked in this file, try to only update the Gem which cause the conflict by using bundle update gem_name and you have to check the ReadMe if any changes needed to work with the new version otherwise you are breaking your code or others code.
I found that by removing the specified version of rails solved the problem for me ....
instead of:
gem rails, '4.0.4'
I did
gem rails
followed by deleting the Gemfile.lock and re-running bundle install
If deleting Gemfile.lock doesn't work there is another possibility:
It may be possible a gem you are depending on has inadvertently included its own Gemfile.lock in its .gem file. The solution is to update the offending gems to not include a Gemfile.lock, rebuild and reinstall.
An alternative is to go to your Gemfile.lock and delete all references to the offending gem (in this case the faraday gem).
Then run bundle install and it'll update the Gemfile.lock to have compatible versions of the gem where it needs.
If you want to be extra safe you can go to the Gemfile and specify the versions of the gems you want before doing this.
This was the only way I was able to get bundle install running for one of the systems that I'm maintaining.
This system has a lot of old gems in its dependencies (58 gems at the time of writing) and so bundler has a hard time coping with it.
If I delete the Gemfile.lock and run bundle install it'll blow up with multiple Bundler could not find compatible versions for gem xxxxxx errors.
If I run bundle update it would also blow up with multiple Bundler could not find compatible versions for gem xxxxxx errors.
Note: Removing Gemfile.lock will have new entried to different gems. This might not be acceptable in your project. Your team or lead will not allow this.
If you are working on legacy codebase, for example Rails 3.2 or similar
In case you hit this kind of errors,
see the last line of Gemfile.lock which seems like
whenever (~> 0.9.4)
wicked_pdf (= 1.1.0)
will_paginate (= 3.1.8)
wkhtmltopdf-binary-edge (~> 0.12.4.0)
BUNDLED WITH
1.16.6
now install the version of bundler mentioned in the file. In my case its1.16.6.
gem install bundler -v 1.16.6
now remove the older version. How?
$ gem uninstall bundler
Select gem to uninstall:
1. bundler-1.16.6
2. bundler-2.1.4
3. All versions
> 2
Successfully uninstalled bundler-2.1.4
$ bundle -v
Bundler version 1.16.6
Now it will install successfully