bundle exec - 你已经激活了json X,但是你的Gemfile需要json Y

时间:2017-03-29 11:50:27

标签: json rubygems bundler

尽管使用了 bundle exec 前缀,但是当我收到此错误时,尝试在Windows上执行gegwin(x64)上的jekyll。

执行时不应激活Gemfile中定义的依赖关系(即1.8.6)吗?

对这里出了什么问题的想法?我对Ruby宝石的世界全新。我查看了其他“你已经激活了......”帖子显示了类似的消息,但那里的答案并没有解决我的问题。

$ 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)

环境

  • 在Windows 7上安装Cygwin x86_64
  • 安装在Cygwin上的RVM
$ 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 - 适用于jekyll项目

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
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!

捆绑exec - 完整的错误消息

$ 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)

捆绑show json

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

无法卸载默认宝石

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

更新 - 2017年4月12日

我不知道问题到底是什么,但是我将Gemfile减少到了这个并且它不会落入堆中。当这些特定的版本依赖关系没有得到强制执行时,它可能会以某种方式运行。

source 'https://rubygems.org'

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

更新 - 2017年4月21日

此问题与bundler和系统宝石突出显示at Gem Versioning and Bundler - Doing it right

  

Bundler的沙箱依赖于它在Ruby进程一开始就存在的能力,因此能够确保所有已加载库的版本都能反映Gemfile.lock中列出的版本。通过运行系统可执行文件,您可以在Bundler修改加载路径并替换正常的Rubygems加载机制之前执行Ruby代码,从而允许任意非托管gem加载到内存中。 一旦发生这种情况,所有投注均已关闭。

这种情况似乎正在发生。

但是,如上所述 - 无法卸载系统json 2.0.2 gem。

2 个答案:

答案 0 :(得分:6)

游戏有点晚了,但是,嘿,我有一个解决方案!这就是我这样做的方式:所以除了查看安装宝石的标准位置外,还有一个地方可以明显地“定义”宝石,并将其带入系统。我使用rbenv安装东西(我建议通过RVM),这些是我的目录:

/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

在您的情况下,您的确切位置可能会有所不同,但您应该能够弄明白。如果某个宝石位于标准位置(/home/jf/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems),您就可以毫无问题地进行“宝石卸载”。对于其他位置,虽然......很难。要简单地阻止系统版本被识别以便您可以使用Gemfile中的版本,只需将json-X.gemspec文件从其他位置的第二个目录(上面的/home/jf/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/specifications/default)移开。就是这样!

答案 1 :(得分:-4)

昨天我遇到了同样的问题。我不是专家,但以下工作对我有用:

我使用Jekyll创建了一个新网站:

$ jekyll new "name_site" 

然后我将新的GemFile和GemFile.lock从新文件夹复制到较旧的文件夹(您遇到问题)。然后,你运行:

$ jekyll serve 

在您当前网站的文件夹中,它应该有效。让我知道它是否适合你!