我使用sudo捆绑安装,这可能是问题的原因?

现在我有:

Gem -v 2.6.14 Ruby -v Ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin15] Jekyll -v Jekyll 3.6.2 vbundler版本为1.16.0.pre.3

我得到以下错误时,试图运行捆绑执行jekyll服务或只是jekyll服务

/Users/myusername/.rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems.rb:271:in `find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
    from /Users/myusername/.rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems.rb:299:in `activate_bin_path'
    from /Users/myusername/.rvm/gems/ruby-2.3.5/bin/bundle:23:in `<main>'
    from /Users/myusername/.rvm/gems/ruby-2.3.5/bin/ruby_executable_hooks:15:in `eval'
    from /Users/myusername/.rvm/gems/ruby-2.3.5/bin/ruby_executable_hooks:15:in `<MacBooMacBook-MacBook-MacBook-Pro-MacBook-PrMacBook-MacBooMacBMaMacBMaMaMaMaMaMaMaMaMacBMaMaMaMacBMa

同样,当访问我的博客cd my_path所在的文件夹时,我得到以下消息:

VM使用你的Gemfile来选择Ruby,这一切都很好- Heroku也这样做, 你可以通过'rvm rvmrc warning ignore /Library/WebServer/Documents/blog/Gemfile'忽略这些警告。 要忽略所有文件的警告,请执行'rvm rvmrc warning ignore allGemfiles'命令。 未知ruby解释器版本(不知道如何处理):RUBY_VERSION。

我不知道该怎么解决。我只是想创建我的静态博客,老实说,我不知道Ruby, Gem或Bundle:)所以我很感激一些见解!


当前回答

真正的答案在这里,如果你试图安装bundler 2.0.1或2.0.0,因为bundler需要RubyGems v3.0.0

Yesterday I released Bundler 2.0 that introduced a number of breaking changes. One of the those changes was setting Bundler to require RubyGems v3.0.0. After making the release, it has become clear that lots of our users are running into issues with Bundler 2 requiring a really new version of RubyGems. We have been listening closely to feedback from users and have decided to relax the RubyGems requirement to v2.5.0 at minimum. We have released a new Bundler version, v2.0.1, that adjusts this requirement.

更多信息,请参见:https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html

其他回答

真正的答案在这里,如果你试图安装bundler 2.0.1或2.0.0,因为bundler需要RubyGems v3.0.0

Yesterday I released Bundler 2.0 that introduced a number of breaking changes. One of the those changes was setting Bundler to require RubyGems v3.0.0. After making the release, it has become clear that lots of our users are running into issues with Bundler 2 requiring a really new version of RubyGems. We have been listening closely to feedback from users and have decided to relax the RubyGems requirement to v2.5.0 at minimum. We have released a new Bundler version, v2.0.1, that adjusts this requirement.

更多信息,请参见:https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html

原因是你当前的ruby环境,你得到了一个不同版本的捆绑器在Gemfile.lock的版本。

安全的方法,在Gemfile中安装相同版本的捆绑器。锁,如果有什么不和谐的事情发生,这不会破坏任何东西。 困难的方法,只是删除Gemfile。锁定,并运行bundle install。

这就解决了问题:

删除Gemfile。lock rm Gemfile.lock 重新运行bundle install

编辑:不要在生产中这样做!

对于生产,请参考以下答案: https://stackoverflow.com/posts/54083113/revisions

更新:

根据@noraj的回答和@Niels Kristian的评论,下面的命令应该可以完成这项工作。

gem update --system
bundle install

我写这个是为了防止有人遇到我这样的问题。

宝石安装捆绑器显示,一切安装良好。

Fetching: bundler-1.16.0.gem (100%)
Successfully installed bundler-1.16.0
Parsing documentation for bundler-1.16.0
Installing ri documentation for bundler-1.16.0
Done installing documentation for bundler after 7 seconds
1 gem installed

当我输入bundle时,有一个错误:

/Users/nikkov/.rvm/gems/ruby-2.4.0/bin/bundle:23:in `load': cannot load such file -- /Users/nikkov/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/exe/bundle (LoadError)
    from /Users/nikkov/.rvm/gems/ruby-2.4.0/bin/bundle:23:in `<main>'
    from /Users/nikkov/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/nikkov/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'

在/Users/nikkov/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/文件夹中没有bunder -1.16.0文件夹。

我用sudo宝石安装捆绑器修复了这个问题

我的问题是Gemfile。lock文件的BUNDLED_WITH版本为1.16.1,gem install bundler安装的版本为2.0.1,因此在查找正确的文件夹时存在版本不匹配

Gem install bundler -v 1.16.1修复了它

当然,您也可以更改Gemfile。按照Sam3000的建议,将BUNDLED_WITH锁到最新的捆绑器版本,并使用最新的软件