首页 > 解决方案 > 启动 Ruby on Rails 服务器时如何修复加载错误

问题描述

我经常遇到错误。例如,在运行 SQLite3 服务器时:

$ rails s
C:/Ruby26-x64/bin/rails:23:in `load': cannot load such file -- C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/railties-6.0.2.2/exe/rails (LoadError)
        from C:/Ruby26-x64/bin/rails:23:in `<main>'

我尝试了在这里找到的所有不同建议,例如bundle install rails。我正在运行 Ruby v. 2.6.5,但在上面的错误中提到了 2.6.0。

$ which -a ruby
/c/Ruby26-x64/bin/ruby
/c/RailsInstaller/Ruby2.3.3/bin/ruby

红宝石版本:

$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x64-mingw32]

宝石文件:

`source 'https://rubygems.org'
    git_source(:github) { |repo| "https://github.com/#{repo}.git" }

    ruby '2.6.5'

    gem 'devise', '~> 4.2'
    gem 'simple_form'
    gem 'will_paginate'
    gem 'news-api'
    gem 'httparty'
    gem 'executables'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.2', '>= 6.0.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
  gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
  gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

bin/rails s命令:

$ bin/rails s
bin/rails:4:in `require': cannot load such file -- rails/commands (LoadError)
        from bin/rails:4:in `<main>'

gem 环境命令

    $ gem env
    RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.3
  - RUBY VERSION: 2.6.5 (2019-10-01 patchlevel 114) [x64-mingw32]
  - INSTALLATION DIRECTORY: C:/Ruby26-x64/lib/ruby/gems/2.6.0
  - USER INSTALLATION DIRECTORY: C:/Users/darre/.gem/ruby/2.6.0
  - RUBY EXECUTABLE: C:/Ruby26-x64/bin/ruby.exe
  - GIT EXECUTABLE: C:\Program Files\Git\mingw64\bin/git.EXE
  - EXECUTABLE DIRECTORY: C:/Ruby26-x64/bin
  - SPEC CACHE DIRECTORY: C:/Users/darre/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData
  - RUBYGEMS PLATFORMS:
    - ruby
    - x64-mingw32
  - GEM PATHS:
     - C:/Ruby26-x64/lib/ruby/gems/2.6.0
     - C:/Users/darre/.gem/ruby/2.6.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - C:\Users\darre\.rbenv\bin
     - C:\Users\darre\bin
     - C:\Program Files\Git\mingw64\bin
     - C:\Program Files\Git\usr\local\bin
     - C:\Program Files\Git\usr\bin
     - C:\Program Files\Git\usr\bin
     - C:\Program Files\Git\mingw64\bin
     - C:\Program Files\Git\usr\bin
     - C:\Users\darre\bin
     - C:\Program Files\ImageMagick-7.0.10-Q16
     - C:\Program Files (x86)\Common Files\Oracle\Java\javapath
     - C:\Windows\system32
     - C:\Windows
     - C:\Windows\System32\Wbem
     - C:\Windows\System32\WindowsPowerShell\v1.0
     - C:\Windows\System32\OpenSSH
     - C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL
     - C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
     - C:\Program Files\Intel\WiFi\bin
     - C:\Program Files\Common Files\Intel\WirelessCommon
     - C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
     - C:\WINDOWS\system32
     - C:\WINDOWS
     - C:\WINDOWS\System32\Wbem
     - C:\WINDOWS\System32\WindowsPowerShell\v1.0
     - C:\WINDOWS\System32\OpenSSH
     - C:\Program Files\Git\cmd
     - C:\Users\darre\AppData\Local\Microsoft\WindowsApps
     - C:\Users\darre\AppData\Local\atom\bin
     - C:\Program Files\Java\jdk1.8.0_111\bin
     - C:\Python27
     - C:\adb
     - C:\Program Files\nodejs
     - C:\Program Files (x86)\Yarn\bin
     - C:\Users\darre\scoop\apps\yarn\current\Yarn\bin
     - C:\Users\darre\scoop\persist\yarn\global\node_modules\.bin
     - C:\Users\darre\scoop\shims
     - C:\Ruby26-x64\bin
     - C:\RailsInstaller\Git\cmd
     - C:\RailsInstaller\Ruby2.3.3\bin
     - C:\Users\darre\AppData\Local\Microsoft\WindowsApps
     - C:\Users\darre\AppData\Local\atom\bin
     - C:\Program Files\Java\jdk1.8.0_111\bin
     - C:\Python27
     - C:\Users\darre\AppData\Local\Programs\Microsoft VS Code\bin
     - C:\Users\darre\AppData\Roaming\npm
     - C:\Users\darre\AppData\Local\Yarn\bin
     - C:\Program Files\heroku\bin
     - C:\Program Files\Git\usr\bin\vendor_perl
     - C:\Program Files\Git\usr\bin\core_perl

标签: ruby-on-railsrubywindows

解决方案


推荐阅读