Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bundle exec - You have already activated json X, but your Gemfile requires json Y

Trying to execute jekyll on cygwin (x64) on Windows when I get this error in spite of using bundle exec prefix.

Shouldn’t the dependency defined in the Gemfile (i.e. 1.8.6) be activated when executing?

Any thoughts on what is going wrong here? I am totally new to the world of Ruby gems. I have looked at other "You have already activated .. " posts showing similar messages but the answers there didn’t solve my problem.

$ bundle exec jekyll serve

$ bundle exec jekyll serve
/cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:40:in
 `block in setup': You have already activated json 2.0.2, but your Gemfile requires json 1.8.6. 
 Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

Environment

  • Cygwin x86_64 installed on Windows 7
  • RVM installed on Cygwin
$ rvm -v
rvm 1.29.0 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]

$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-cygwin]

Gemfile - for the jekyll project

source 'https://rubygems.org'

require 'json'
require 'open-uri'
versions = JSON.parse(open('https://pages.github.com/versions.json').read)

gem 'github-pages', group: :jekyll_plugins
gem 'json', '~> 1.8.0'

$ gem environment

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.10
  - RUBY VERSION: 2.4.0 (2016-12-24 patchlevel 0) [x86_64-cygwin]
  - INSTALLATION DIRECTORY: /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0
  - USER INSTALLATION DIRECTORY: /cygdrive/c/Users/mochapenguin/.gem/ruby/2.4.0
  - RUBY EXECUTABLE: /cygdrive/c/Users/mochapenguin/.rvm/rubies/ruby-2.4.0/bin/ruby.exe
  - EXECUTABLE DIRECTORY: /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/bin
  - SPEC CACHE DIRECTORY: /cygdrive/c/Users/mochapenguin/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /cygdrive/c/Users/mochapenguin/.rvm/rubies/ruby-2.4.0/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-cygwin
  - GEM PATHS:
     - /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0
     - /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/bin
     - /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0@global/bin
     - /cygdrive/c/Users/mochapenguin/.rvm/rubies/ruby-2.4.0/bin
     - /usr/local/bin
     - /usr/bin
     - /cygdrive/c/Windows/system32
     - /cygdrive/c/Windows
     - /cygdrive/c/Windows/System32/Wbem
     - /cygdrive/c/Windows/System32/WindowsPowerShell/v1.0
     - /cygdrive/c/Program Files/Java/jdk1.8.0_121/bin
     ..... snip .....
     - /cygdrive/c/Users/mochapenguin/AppData/Local/atom/bin
     - /usr/lib/lapack
     - /cygdrive/c/Users/mochapenguin/.rvm/bin

bundle update

$ bundle update
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies...
Using i18n 0.8.1
Using json 1.8.6
Using minitest 5.10.1
Using thread_safe 0.3.6
Using public_suffix 2.0.5
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using colorator 1.1.0
Using ffi 1.9.18
Using multipart-post 2.0.0
Using forwardable-extended 2.6.0
Using gemoji 3.0.0
Using net-dns 0.8.0
Using sass 3.4.23
Using rb-fsevent 0.9.8
Using kramdown 1.13.2
Using liquid 3.0.6
Using mercenary 0.3.6
Using rouge 1.11.1
Using safe_yaml 1.0.4
Using mini_portile2 2.1.0
Using jekyll-paginate 1.1.0
Using jekyll-swiss 0.4.0
Using minima 2.0.0
Using unicode-display_width 1.1.3
Using bundler 1.14.6
Using tzinfo 1.2.3
Using addressable 2.5.0
Using coffee-script 2.4.1
Using ethon 0.10.1
Using rb-inotify 0.9.8
Using faraday 0.11.0
Using pathutil 0.14.0
Using jekyll-sass-converter 1.5.0
Using nokogiri 1.7.1
Using terminal-table 1.7.3
Using activesupport 4.2.7
Using jekyll-coffeescript 1.0.1
Using typhoeus 0.8.0
Using listen 3.0.6
Using sawyer 0.8.1
Using html-pipeline 2.5.0
Using jekyll-watch 1.5.0
Using octokit 4.6.2
Using jekyll 3.4.3
Using github-pages-health-check 1.3.3
Using jekyll-gist 1.4.0
Using jekyll-avatar 0.4.2
Using jekyll-default-layout 0.1.4
Using jekyll-feed 0.9.2
Using jekyll-github-metadata 2.3.1
Using jekyll-mentions 1.2.0
Using jekyll-optional-front-matter 0.1.2
Using jekyll-readme-index 0.1.0
Using jekyll-redirect-from 0.12.1
Using jekyll-relative-links 0.4.0
Using jekyll-seo-tag 2.1.0
Using jekyll-sitemap 1.0.0
Using jekyll-theme-architect 0.0.3
Using jekyll-theme-cayman 0.0.3
Using jekyll-theme-dinky 0.0.3
Using jekyll-theme-hacker 0.0.3
Using jekyll-theme-leap-day 0.0.3
Using jekyll-theme-merlot 0.0.3
Using jekyll-theme-midnight 0.0.3
Using jekyll-theme-minimal 0.0.3
Using jekyll-theme-modernist 0.0.3
Using jekyll-theme-primer 0.1.7
Using jekyll-theme-slate 0.0.3
Using jekyll-theme-tactile 0.0.3
Using jekyll-theme-time-machine 0.0.3
Using jekyll-titles-from-headings 0.1.5
Using jemoji 0.8.0
Using github-pages 132
Bundle updated!

bundle exec - Full error message

$ bundle exec jekyll serve
/cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:40:in `block in setup': You have already activated json 2.0.2, but your Gemfile requires json 1.8.6. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
        from /cygdrive/c/Users/mochapenguin/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/forwardable.rb:228:in `each'
        from /cygdrive/c/Users/mochapenguin/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/forwardable.rb:228:in `each'
        from /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:25:in `map'
        from /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:25:in `setup'
        from /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/gems/bundler-1.14.6/lib/bundler.rb:100:in `setup'
        from /cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/gems/bundler-1.14.6/lib/bundler/setup.rb:10:in `<top (required)>'
        from /cygdrive/c/Users/mochapenguin/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /cygdrive/c/Users/mochapenguin/.rvm/rubies/ruby-2.4.0/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

json gems

$ gem list json

*** LOCAL GEMS ***
json (default: 2.0.2, 1.8.6)

bundle show json

$ bundle show json
/cygdrive/c/Users/mochapenguin/.rvm/gems/ruby-2.4.0/gems/json-1.8.6

Can't uninstall a default gem

$ gem uninstall json -v2.0.2
ERROR:  While executing gem ... (Gem::InstallError)
    gem "json" cannot be uninstalled because it is a default gem

UPDATE - 12-Apr-2017

I don't know what the issue is still, but I trimmed down the Gemfile to this and it doesn't fall in a heap. Maybe it somehow works when those particular version dependencies are not enforced.

source 'https://rubygems.org'

# sample suggested [here](https://jekyllrb.com/docs/github-pages/) and in github help
gem 'github-pages', group: :jekyll_plugins

UPDATE - 21-Apr-2017

This issue with bundler and system gems is highlighted at Gem Versioning and Bundler - Doing it right

Bundler's sandbox relies on its ability to be present at the very beginning of the Ruby process, and to therefore have the ability to ensure that the versions of all loaded libraries will reflect the ones listed in the Gemfile.lock. By running a system executable, you are executing Ruby code before Bundler can modify the load path and replace the normal Rubygems loading mechanism, allowing arbitrary unmanaged gems to get loaded into memory. Once that happens, all bets are off.

This is what seems to be happening in this situation.

But, as mentioned above - can't uninstall the system json 2.0.2 gem.

like image 885
JetStream Avatar asked Mar 29 '17 11:03

JetStream


People also ask

What version of JSON is required for a Gemfile?

Gem::LoadError: You have already activated json 1.8.0, but your Gemfile requires json 1.7.7. Using bundle exec may solve this. · Issue #378 · basecamp/pow · GitHub

Why am I getting a warning when I use bundle exec?

Using bundle exec is the right way to do this. Basically what's happening is that you've updated rake to 0.9.2 which now conflicts with the version specified in your Gemfile. Previously the latest version of rake you had matched the version in your Gemfile, so you didn't get any warning when simply using rake.

How do I use gems specified in the Gemfile?

Essentially, if you would normally have run something like rspec spec/my_spec.rb, and you want to use the gems specified in the Gemfile (5) and installed via bundle install (1), you should run bundle exec rspec spec/my_spec.rb. Note that bundle exec does not require that an executable is available on your shell's $PATH.

What does bundle exec do in Ruby?

bundle exec makes a number of changes to the shell environment, then executes the command you specify in full. It also modifies Rubygems: Finally, bundle exec also implicitly modifies Gemfile.lock if the lockfile and the Gemfile do not match.


1 Answers

A bit late to the game, but hey, I have a solution! this is how I did it: so besides looking in your standard place where gems are installed, there is one other place where gems can apparently be "defined", and brought into the system. I install stuff using rbenv (I recommend this over RVM), and these are the directories for me:

/home/jf/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems
/home/jf/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/specifications/default

In your case, your exact location/s might be different, but you should be able to figure it out. If a gem is in the standard place (/home/jf/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems), you would be able to 'gem uninstall' without a problem. For the other location, though... tough. To simply prevent the system version from being recognized so that you can use the version from the Gemfile, simply move the json-X.gemspec file away from that second directory (/home/jf/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/specifications/default above) somewhere else. And that's it!

like image 166
Jeffrey 'jf' Lim Avatar answered Sep 30 '22 01:09

Jeffrey 'jf' Lim