Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'bundle exec' complains about gem not being installed, even after 'bundle install'

Tags:

ruby

bundler

gem

I have a website using Jekyll with Github Pages. After previously messing about with versions and RVM on another computer, on this one I opted to stick with just one version of Ruby and per-project environments using bundler.

I have a pretty simple Gemfile:

[$]> cat Gemfile
source 'https://rubygems.org'
gem 'github-pages'

and bundler config:

[$]> cat .bundle/config
---
BUNDLE_PATH: env
BUNDLE_DISABLE_SHARED_GEMS: '1'

When I run any command (jekyll, gem, irb) through bundle exec, I get a dependency error:

[$]> bundle exec jekyll
Could not find RedCloth-4.2.9 in any of the sources
Run `bundle install` to install missing gems.

However, the bundle is already installed:

[$]> bundle install
Using RedCloth 4.2.9
Using i18n 0.6.11
Using json 1.8.1
[snip]
Using github-pages 29
Using bundler 1.7.7
Your bundle is complete!
It was installed into ./env

I'm at a bit of a loss as to how bundler can think the gems are installed when using one subcommand, but think they're missing when using another.

[$]> which ruby
/usr/local/bin/ruby
[$]> which bundler
/usr/local/bin/bundler
[$]> ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
[$]> bundler --version
Bundler version 1.7.7
like image 726
Xiong Chiamiov Avatar asked Jan 27 '15 20:01

Xiong Chiamiov


People also ask

What is the difference between gem install and bundle install?

Almost seems like running 'gem install' adds it to the global available gems (and hence terminal can run the package's commands), whereas adding it to the gemfile and running bundle install only adds it to the application. Similar to npm install --global. that's basically it.

What is the difference between bundle install and bundle update?

The most common question I've heard about Bundler is about the difference between bundle install and bundle update . In a nutshell: bundle install handles changes to the Gemfile and bundle update upgrades gems that are already managed by Bundler.

How do I resolve gem dependencies?

Common Attempts To Resolve Ruby Gem Dependencies Bundler can help to resolve dependencies when working with Ruby gems by allowing you to specify a set of gems in a Gemfile, then issue a single command to install them. Bundler then automatically resolves the dependencies for you.


2 Answers

After deleting the env directory and reinstalling, I noticed it created subdirectories for two Ruby versions - 2.1.0 and 2.2.0. The latter was my current version of Ruby, but the directory was empty (all the gems were installed into the env/ruby/2.1.0/gems directory). This, combined with Oliver's answer about rbenv, got me thinking about mismatched versions.

I reinstalled bundler with a simple gem install bundler, reran bundle install, and all is good.

It seems in general the answer is to sort out issues with bundler installing for a different version of Ruby than you're actually using. It seems strange to me it would use one thing for bundle install and another for bundle exec, but *shrug* whatever.

like image 79
Xiong Chiamiov Avatar answered Sep 17 '22 19:09

Xiong Chiamiov


I had exactly the same problem after installing rbenv as my Ruby manager. In the end I solved the problem with:

rbenv rehash

(additionally you may need to restart terminal, as per @joel-glovier's comment)

That fact it's complaining about Redcloth 4.2.9 is actually a red herring. Bundler probably can't find any of the gems but Redcloth is the first one it looks for and so it exits imediately with that error.

Basically I'd installed rbenv and ruby 2.2.2 and changed to that version with rbenv global 2.2.2 but I'd forgotten to run rbenv rehash. So I'm guessing when running bundle install it was looking at my previously used version of ruby (system ruby) to see what gems were installed but when running bundle exec jekyll serve it was looking at my new ruby version and not finding any of the gems.

like image 25
Oliver Pearmain Avatar answered Sep 18 '22 19:09

Oliver Pearmain