ruby 我在创建新的Rails应用程序(rails new name_project)时遇到错误

vsdwdz23  于 2023-08-04  发布在  Ruby
关注(0)|答案(2)|浏览(94)

因此,我通过这个视频(https://www.youtube.com/watch?v=fmyvWz5TUWg&t=9163s&ab_channel=freeCodeCamp.org)安装了Ruby和Rails,并使用命令rails new <name of the project>制作了一个新的Rails应用程序。在最后,应用程序被创建,但在最后有这些错误:

Bundle complete! 15 Gemfile dependencies, 73 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
       rails  importmap:install
C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:442:in `validate_ruby!': Your                                                                                                                                 
Ruby version is 3.2.2, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMi                                                                                                                                  smatch)
from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:417:in `validate                                                                                                                                  _runtime!'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler.rb:165:in `setup'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `block in <top                                                                                                                                   (required)>'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:159:in `with_level                                                                                                                                  '
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:111:in `silence'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `<top (required                                                                                                                                  )>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req                                                                                                                                  uire.rb>:85:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req                                                                                                                                  uire.rb>:85:in `require'
        from D:/railsfriends/friends/config/boot.rb:3:in `<top (required)>'
        from bin/rails:3:in `require_relative'
        from bin/rails:3:in `<main>'
       rails  turbo:install stimulus:install

C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:442:in `validate_ruby!': Your                                                                                                                                   
Ruby version is 3.2.2, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMi                                                                                                                                  smatch)
from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:417:in `validate                                                                                                                                  _runtime!'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler.rb:165:in `setup'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `block in <top                                                                                                                                   (required)>'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:159:in `with_level                                                                                                                                  '
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:111:in `silence'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `<top (required                                                                                                                                  )>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req                                                                                                                                  uire.rb>:85:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req                                                                                                                                  uire.rb>:85:in `require'
        from D:/railsfriends/friends/config/boot.rb:3:in `<top (required)>'
        from bin/rails:3:in `require_relative'
        from bin/rails:3:in `<main>'

字符串
看起来这个错误是关于ruby的版本的,但是我应该怎么做来解决这个问题呢?这个错误会以任何方式影响我吗?

编辑

我打开项目的Gemfile,从ruby“3.1.2”改为ruby“3.2.2”,然后删除整个项目,并使用rails new <project_name>重新创建一个新项目。然后我得到了这个

Bundle complete! 15 Gemfile dependencies, 73 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
       rails  importmap:install
Add Importmap include tags in application layout
      insert  app/views/layouts/application.html.erb
Create application.js module as entrypoint
      create  app/javascript/application.js
Use vendor/javascript for downloaded pins
      create  vendor/javascript
      create  vendor/javascript/.keep
Ensure JavaScript files are in the Sprocket manifest
      append  app/assets/config/manifest.js
Configure importmap paths in config/importmap.rb
      create  config/importmap.rb
Copying binstub
      create  bin/importmap
       rails  turbo:install stimulus:install
Import Turbo
      append  app/javascript/application.js
Pin Turbo
      append  config/importmap.rb
Create controllers directory
      create  app/javascript/controllers
      create  app/javascript/controllers/index.js
      create  app/javascript/controllers/application.js
      create  app/javascript/controllers/hello_controller.js
Import Stimulus controllers
      append  app/javascript/application.js
Pin Stimulus
Appending: pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true"
      append  config/importmap.rb
Appending: pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
      append  config/importmap.rb
Pin all controllers
Appending: pin_all_from "app/javascript/controllers", under: "controllers"
      append  config/importmap.rb
Run turbo:install:redis to switch on Redis and use it in development for turbo streams


现在,当我检查这个新创建的项目的Gemfile时,它现在有ruby“3.2.2”。现在一切正常吗

rks48beu

rks48beu1#

检查你的安装版本与ruby -v在终端,也检查一个文件challed Gemline,有一个ruby版本在这个文件。您安装的ruby版本和Gem文件的ruby版本必须相同

ghhaqwfi

ghhaqwfi2#

简单的答案就是你可以在Gemfile中修改版本要求,或者安装Gemfile指定的版本。
然而,我强烈建议你删除你的ruby安装,安装一个ruby版本管理器(RVM,或者可能是现在更流行的RBenv),并以这种方式管理你的ruby安装。在Ruby冒险中,早期做这件事要比后期做容易得多。

相关问题