我使用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:)所以我很感激一些见解!


当前回答

安装与您的Gemfile匹配的捆绑器。锁的使用:

gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"

其他回答

真正的答案在这里,如果你试图安装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

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

Gem install bundler -v 1.16.1修复了它

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

gem update --system

将更新rubygems并修复这个问题。

在我的情况下,上述建议对我不起作用。我的情况有点不同。

当我尝试使用gem安装bundle安装bundle ..但我正在

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

然后我尝试使用sudo宝石安装捆绑器,然后我得到

ERROR:  While executing gem ... (Gem::FilePermissionError)
  You don't have write permissions for the /usr/bin directory.

然后我尝试用sudo gem安装捆绑器-n /usr/local/bin(只是/usr/bin力在我的情况下工作)。

然后成功安装了捆扎机

编辑:我使用MacOS,也许/usr/bin不适合我的原因(https://stackoverflow.com/a/34989655/3786657评论)

我的问题是我正在使用RVM并且激活了错误的Ruby版本…

希望这能帮助到至少一个人