How to install (ruby) bundler when bundler is broken - ruby

After adding
gem "ransack", :git => "git://github.com/ernie/ransack.git"
to my gemfile, I now get the error message :
git://github.com/ernie/ransack.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError)
for any rails <>, bundle, or gem command.
This is with bundler version 1.0.21.
I see there is now version 1.30 on github, but the install "instructions" on the bundler site, seem to imply that it using an existing bundler to set up the new version?
http://gembundler.com/
require "rubygems"
require "bundler"
Bundler.setup(:default, :ci)
require "nokogiri"
How can I un-install the existing (broken) bundler, and install the new version, without an older version present ?
Mike

Bundler is just a gem like any gem, and there is no need to use Bundler to install Bundler, regardless of what the instructions tell you. It's as simple as:
gem uninstall bundler
gem install bundler
If you are using RVM, there may be a little more to it than this (you may have to switch to the 'global' gemset first), but not much.

Related

Unable to require gem from git with RVM

I cannot require a custom gem I developed to a ruby project. I use RVM. Here's what I've done:
I added gem locally via Gemfile:
gem 'my-gem', git: 'https://github.com/username/my-gem.git'
I installed the gem:
bundle
Fetching https://github.com/username/my-gem.git
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using my-gem 0.1.0 https://github.com/username/my-gem.git (at master#dcdac02)
Using bundler 1.11.2
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
I confirmed it was installed:
bundle show my-gem
/Users/myuser/.rvm/gems/ruby-2.2.2/bundler/gems/my-gem-dcdac02a8b69
I confirmed my gem paths:
GEM PATHS:
- /Users/myuser/.rvm/gems/ruby-2.2.2
- /Users/myuser/.rvm/gems/ruby-2.2.2#global
When I run gem list, my gem is missing. When I require 'my-gem', the gem cannot be found.
When I run gem which my-gem, I get:
ERROR: Can't find ruby library file or shared library my-gem
I'm not really sure what else to try. Any ideas?
Rubygems have no concept of git installed gems, so Bundler includes a specific mechanism for loading these paths into the GEMPATH, you need to do the following before you can require them:
require 'bundler'
Bundler.setup
See the Bundler git gems docs for more info.
I would make sure the installed version of the gem has all the files you expect, especially lib and its contents. This past discussion might help you:
gem which cannot find gem despite it being installed
I found a similar issue
bundle show kubernetes_metadata_filter
/fluentd/vendor/bundle/ruby/2.3.0/bundler/gems/fluent-plugin-kubernetes_metadata_filter-0cd7e29eacec
while the rest of my gems were install here:
/fluentd/vendor/bundle/ruby/2.3.0/gems/
notice the subtle difference between 2.3.0/bundler/gems/... and 2.3.0/gems/......
HACKY SOLUTION:
after bundle install, i did the following:
gem install specific_install
gem specific_install -l <url to a github gem>
That did the trick and installed the gem to the gems directory, and not just bundler. I beleive the correct fix is the project needs to require bundler on startup, then it will get the bundler installed gems as well, but not all projects are well suited for that solution. good luck!

Error on require 'motion-cocoapods' with RubyMotion

I just got Ruby motion, and I wanted to try out Cocoapods. I installed it just as it asks on the website:
http://www.rubymotion.com/developer-center/articles/cocoapods/
I add
require 'motion-cocoapods' to my simple 'Hello' project. And I get this error when trying to rake it:
rake aborted!
Unable to activate cocoapods-0.16.1, because rake-10.0.3 conflicts with rake (~> 0.9.4)
I guess this has something to do with my version of rake, but I have no idea what I need to do to fix this problem. Please help!
This is caused by having a version of rake newer than 0.9.x installed. When you just run rake, it loads up the newest version (10.0.3 in your case). Then, when the cocoapod gem tries to load, it tries to activate rake 0.9.x and fails (the ~> 0.9.4 means that it will accept any version starting with 0.9.).
One solution would be to completely remove the rake gem and install the 0.9.4 version explicitly:
gem uninstall rake
gem install rake --version '0.9.6'
However, this could become an issue if you have any other projects that require a newer version of rake. A better solution would be to use Bundler:
gem install bundler
Create a Gemfile in your project folder containing:
source :rubygems
gem 'rake'
gem 'motion-cocoapods'
Add the following to Rakefile, immediately under the require 'motion/project' line:
require 'bundler'
Bundler.require
Then run bundle install from the console. This will lock this specific project on rake 0.9.6. The only catch is that you'll probably need to prefix all of your rake commands with bundle exec.
I was able to solve this issue by following the steps on this japanese blog:
http://blog.amacou.net/post/37702092871/rubymotion-cocoapods-rake
First uninstall:
gem uninstall motion-cocoapods
gem uninstall cocoapods
download cocoapods :
git clone git://github.com/CocoaPods/CocoaPods.git
find the gemspec file
and change this:
s.add_runtime_dependency 'rake', '~> 0.9.4'
to this:
s.add_runtime_dependency 'rake', '> 0.9.4'
then install it as a gem
rake gem:install
then reinstall motion-cocoapods:
gem install motion-cocoapods
My feeling is this is a hack though, and I'm worried it could cause problems else where. If anyone has a better answer, please post it.

Including the bundler gem itself in my Rails app

Bundler is great. But there's one gem that it won't work for, and that's the bundler gem itself, which still needs to be installed manually:
Could not load the bundler gem. Install it with `gem install bundler`.
Besides being an extra step, this opens the door to version incompatibilities with Bundler itself.
Is there a way to include Bundler itself in my app, so that it relies on the included bundler gem?
No. The ruby gems stay on the user environment, you can't distribute it with your project, the user need to install the bundler.
and Bundler can't bundle itself. :)

How do I install a Ruby gem from GitHub and have it work in IRB?

Seems like every Ruby tutorial I find centers around Rails.
Anyway, I simply want to install a gem from a GitHub repo and have that gem work in irb.
I want to install the exifr gem. When I do a gem install exifr it doesn't get the newest version.
So I created a Gemfile and put:
gem 'exifr', :git => 'git://github.com/remvee/exifr.git'
Then bundle install. Installs OK but now gem list doesn't find the gem. So I can't require it in irb.
Any help for NON Rails applications?
Thanks
You need to kick off the bundler setup if you want to use the gems from a gemfile:
require 'bundler/setup'
require 'exifr'
or:
irb -rbundler/setup
> require 'exifr'
This is equivalent to running bundle exec irb, except it doesn't depend on a specific invocation to work, and instead presumes that a Gemfile is available and the gems were installed with Bundler.
Try...
bundle exec gem list
And..
bundle exec irb -rexifr
And see if that works. That should help gem/irb find the installed gem.

Problems with bundled gems and datamapper: conflict with muti_json version?

I have a site running with nginx/unicorn/sinatra (bundler/rvm).
After my last bundle update, I am getting an error:
in `raise_if_conflicts': Unable to activate dm-serializer-1.2.1, because multi_json-1.3.5 conflicts with multi_json (~> 1.0.3)
My Gemfile is:
source "http://rubygems.org"
gem 'unicorn'
gem 'sinatra'
gem 'datamapper'
gem 'dm-mysql-adapter'
gem 'haml'
gem 'sass'
gem 'omniauth-twitter'
Gemfile.lock does not have any reference to multi_json 1.0.3
Any ideas?
Solution was:
check Gemfile.lock to see which gem(s) bring in later version (in this case - omniauth-twitter)
Find a version of 'offender' that does not require too high version
Rollback later versions, lock to a proper version in Gemfile
In this particular case, Gemfile that works needed lines:
gem 'omniauth-twitter', '0.0.9'
gem 'multi_json', '~> 1.0.3'
One of the gems in your bundle has an older version of multi_json as a dependency it looks like. See if bundle viz tells you. You'll need to install the ruby-graphviz gem and graphviz itself if you don't have them installed already, though.
Another way to see what's up is to add multi_json to your gemfile at the version you're trying to upgrade to, then do a bundle install and see what errors come out.
This is how to fix this problem:
rvm uninstall multi_json
It will tell you that you have many versions installed, show you a list of them, and ask you which one exactly you want to uninstall.
Try the first one, if it tells you that it is used by some other gem, try the second one, and so on. Keep deleting all the unused versions until only one remains.
This is how I do it, but there may be some clearner solution. If anyone knows it, thanks for sharing it with us.

Resources