Ruby Gems not found despite bundle install - ruby-on-rails

I have a Rails app. My collaborator updated the app's Ruby version and added Gems. I had to update my local version of Ruby to 2.3.1.
Now it seems that rails s looks for gems in a different location than where bundle install puts them. What do I have to do to get both to put and look for gems in the same place?
Concretely, when I try to start the Rails server with
rails s
I get the message
/Users/Falk/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'railties' (>= 0) among 5 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/Falk/.gem/ruby/2.3.0:/Users/Falk/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0', execute `gem env` for more information
from /Users/Falk/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
from /Users/Falk/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
from /usr/local/bin/rails:22:in `<main>'
This happens even though I have already run
bundle install
and all the required gems are included in the gem file. I was able to make progress by manually uninstalling and reinstalling individual gems through
gem uninstall <gem_name>
gem install <gem_name>
but it kept on complaining about one missing gem after another. Then I uninstalled all gems using
for x in `gem list --no-versions`; do gem uninstall $x -a -x -I; done
After that, bundle install still acts as if all gems were already installed. But rails s still does not work and complains about missing gems. What should I do now?

I was able to solve this problem by following the steps outlined here:
bundle uses wrong ruby version

Go to the service/repository that you are trying to run, and go to bin/bundle file. open the file and you will find a code snippet like this :
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
Change the path to your gemfile as is mentioned here, after which in your service/repository you will find your gemfile. By checking its source provide the right directory path. After which include all your gems into the gem file, like this:
gem 'protobuf'
gem 'grpc'
gem 'protobuf-activerecord'
Finally use
bundle list
to check if the bundler has all the gems initialised in it.

Related

Error while installing jekyll and want to remove ruby related files on mac osx

I was trying to install jekyll on my Mac(OS X 10.11.2) to start my blog with a static page, following this instruction (sorry it's written in Korean)
I think I made a mistake when I typed (I typed the wrong URL)
git remote add origin URL
I wanted to delete jekyll and restart from the beginning so I did,
gem uninstall jekyll
and
gem cleanup gems
then the error message showed up like this
/Library/Ruby/Site/2.0.0/rubygems/dependency.rb:318:in `to_specs': Could not find 'jekyll' (>= 0) among 26 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/MYNAME/.gem/ruby/2.0.0:/Library/Ruby/Gems/2.0.0:/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0', execute `gem env` for more information
from /Library/Ruby/Site/2.0.0/rubygems/dependency.rb:327:in `to_spec'
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
from /usr/local/bin/jekyll:22:in `<main>'
I tried installing rbenv with homebrew and every solution I looked up for but nothing has changed.
Is removing all the ruby related files and reinstalling is the only way to solve this problem? If so, how can I do that?
Okay, for your problem only try this:
sudo gem uninstall jekyll
The reason is you have installed this gem into sudo's gemset and tried to remove it from user's gemset. They are different.

Rails Bundle Install Not Finding Gem

I'm having a problem with the rails
bundle install
command not being able to find a local gemfile.
The gem is located here::
~/.gem/ruby/2.1.5/gems/mygemname-1.5.0.SNAPSHOT
I included the gem in my Gemfile. But when I try to bundle my application, it get this error::
Could not find gem 'mygemname-1.5.0.SNAPSHOT' (>= 0) ruby' in the gems available on this machine.
I can see the gem sitting on my hardrive, but the bundle install command says it doesn't exist. Does anybody have any ideas on what may be going on here?
Thanks for your time.
As I canĀ“t comment yet...
I would check:
- Is it really the .gem folder holding the gem or is it symlinked (I am not confident that symlinks work on bundle install)
- Is rbenv or rvm in the game and is the installed gem installed with one of those or globally?

Remove gem installed via Bundler from Git/Github

In my Rails app, I have installed the gem sdoc from Github by specifying gem 'sdoc', github: 'voloko/sdoc' in my Gemfile. All was well until I recently updated Bundler to v1.6.0.rc.
Now I get the following error message when Bundler tries to load the gem:
There was a LoadError while loading sdoc.gemspec:
cannot infer basepath from
/Users/manuel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/sdoc-1a0e80c2d629/sdoc.gemspec:2:in `require_relative'
Does it try to require a relative path? That's been removed in Ruby 1.9.
I've already fixed the issue and submitted a pull request, but I cannot get rid of the "broken" gem!
This is what I tried:
removing the gem from the Gemfile or setting it to a different version
removing Gemfile.lock
deleting the gem folder /Users/manuel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/sdoc-1a0e80c2d629
gem uninstall sdoc (It doesn't even appear in gem list)
Nothing helped, every time I do bundle install or bundle update afterwards, I get the same error.
Any hints?
First-off: Clarifying a few things
From the Bundler documentation:
Because Rubygems lacks the ability to handle gems from git, any gems installed from a git repository will not show up in gem list. They will, however, be available after running Bundler.setup
Also, after deleting the gem inside the . . . /bundler/gems/ directory, you also should run rbenv rehash. This should get rid of the gem for you.
Answer:
Go to the root directory of your project (where the Gemfile resides) and run bundle clean. You have to pass either --path or --force switches. This should remove gems installed via git (usually if you have those gems installed and listed by gem list).
If you have issues. Delete the directories manually as you already tried and run rbenv rehash.
If I were you I would downgrade Bundler (ie. uninstall the RC release and install the latest stable).

How can a gem be shown in "bundle show" but not be in the Gemfile?

Running
bundle show
Lists rake (10.0.4) and i18n (0.6.1) amongst other gems, however they are not listed in the Gemfile. Why / how are [gems which aren't in the Gemfile] listed?
The problem I'm having is that one machine (mac osx) following bundle install, has all these gems which are necessary for the rails application to run, whereas another machine (ubuntu 13.04) does not get these non-Gemfile gems.
I am using rbenv and bundler to manage dependencies. I believe this is a problem with my understanding of gemfiles
Each gem you add to the Gemfile can have dependencies. You can check out the Gemfile.lock to see them. Bundler will install these dependencies even though they are not specifically listed in the Gemfile. For more info, you can view the bundler site.

Difference between bundle show gemname and gem list gemname

If I do gem list rack-cache in rails command prompt then it shows no gem with that name but if I do bundle show rack-cache then it gives me the path like /vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2 of where the gem is stored.
I didn't understood this behavior because if the gem is present in the path with the latter command then why its not showing when I gives gem list rack-cache command.
What's the difference.
The confusion comes from the issue bundler is solving.
When you install Gems into your system-wide gem repository you end up with multiple versions of the gem once you have a couple of apps.
So for example you could end up with 3 Rails versions: 3.2.8, 3.2.6 and 3.1.0
If you do a require rails rubygems could use any of these versions and you'll end up with confusion if your App that was initially built against 3.1.0 isn't compatible with some change s in 3.2.8.
What bundler does is install exactly the gems that are specified in the Gemfile.lock and locks those down for the use of that app. Bundler therefore modifies the load-paths for rubygems so only the Gems in the Gemfile.lock are really available to the app.
Therefore bundle install is not installing gems into the system-wide gem directory but rather installs to a different path for each project. That's why you see the gem in a bundler directory and not system wide.
If you install rack-cache through gem install you'll also see it in gem list.
There is a small difference between bundle show and gem list
bundle show will list all the gems which are installed in your current application[you can see them in Gemfile.lock file],where as gem list will list all the gems installed under any gemset which is set to be using.
bundle show gem_name will give path where it is.
gem list gem_name will give same gem_name with all versions installed into your local gems or gemset.
bundle show :
Shows all gems that are part of the bundle, or the path to a given gem
$ bundle show [GEM] [--paths]
When in development mode on your mac, the gems still get installed in the default gem path, whereas in production mode, they get installed in a folder specific to your project. Try doing a bundle show rails on each machine and you'll see what I mean.
When you run gem list it looks in the main gem folder, and since your production gems are sitting in a project-specific folder, the global gem command doesn't know to look there. So you will need to do a bundle exec to run any of those project-specific gemscommands on the server. For my purposes, I created a be alias to bundle exec. Also, to list your project's gems, you can do bundle list.
See http://gembundler.com/rationale.html#deploying-your-application for the rationale behind this

Resources