Rails console:你必须使用 Bundler 2 或更高版本来处理这个锁文件

Rails console: You must use Bundler 2 or greater with this lockfile

我正在尝试在 OpenAppAcademy Rails 上开始学习 Ruby 但是当我 运行 在 18.04 Ubuntu rails console 的终端上时我得到

/var/lib/gems/2.5.0/gems/railties-6.1.4.1/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Traceback (most recent call last):
        5: from bin/rails:3:in `<main>'
        4: from bin/rails:3:in `load'
        3: from /mnt/c/Users/RedmiBook/Desktop/projects/APPACADEMY/SQL/Active Record/Intro To Rails/bin/spring:10:in `<top (required)>'
        2: from /mnt/c/Users/RedmiBook/Desktop/projects/APPACADEMY/SQL/Active Record/Intro To Rails/bin/spring:10:in `new'
        1: from /usr/lib/ruby/vendor_ruby/bundler/lockfile_parser.rb:95:in `initialize'
/usr/lib/ruby/vendor_ruby/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)

我的捆绑器高于版本 2,所以我尝试 sudo gem update --system

Installing RubyGems 3.2.27
Traceback (most recent call last):
        3: from setup.rb:22:in <main>'
        2: from setup.rb:22:in require'
        1: from /var/lib/gems/2.5.0/gems/rubygems-update-3.2.27/lib/rubygems.rb:1328:in <top (required)>'
/var/lib/gems/2.5.0/gems/rubygems-update-3.2.27/lib/rubygems.rb:1341:in rescue in <top (required)>': uninitialized constant Gem::BasicSpecification (NameError)
Loading the rubygems/defaults/operating_system.rb file caused an error. This file is owned by your OS, not by rubygems upstream. Please find out which OS package this file belongs to and follow the guidelines from your OS to report the problem and ask for help.

我真的不知道该何去何从,很遗憾我无法开始使用 rails。

根据您安装 ruby 的方式(rvmrbenvasdf、系统级安装),您可能需要预先添加 bundle exec您的 ruby 命令:

bundle exec rails console

这样 bundle 将限制执行您在 Gemfile.lock 中声明的 gem,可能包括 bundle 版本。

您可能全局安装了 rails 可执行文件,它可能使用不同版本的 ruby 和 rubygems。


更新(关于以用户友好的方式安装ruby的痛苦):

我绝对建议您安装一些用户级工具链,如 rvmasdf 并完全控制 ruby 版本。您不应该 sudo 向 运行 ruby 和 rails 应用程序发送任何内容。

转到 rvm 或 asdf 站点并按照说明将它们安装到您的操作系统中,这样您就可以控制 ruby。