railse 专案运行时错误:can't activate sqlite3 (~> 1.3.6)

环境

Rails 5.2.2
ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]

问题

当rails、ruby、sqlite3都安装完成,顺利创建完专案的时候,运行服务访问专案时又报了一个错

Puma caught this error: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile. (LoadError)
C:/Ruby25/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem'
……

这是我在网上找了一个解决方案

修改Gemfile文件
gem 'sqlite3', '~> 1.3.6'
改完之后运行命令
bundle install
安装完成后
rails s
结果服务没起来

又报了下面的错误

Traceback (most recent call last):
        22: from bin/rails:4:in `
' 21: from bin/rails:4:in `require' 20: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands.rb:18:in `' 19: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/command.rb:46:in `invoke' 18: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/command/base.rb:65:in `perform' 17: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch' 16: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command' 15: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run' 14: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:142:in `perform' 13: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/railties-5.2.2/lib/rails/commands/server/server_command.rb:142:in `tap' 5: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:76:in `each' 4: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require' 3: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:81:in `require' 2: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:2:in `' 1: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:6:in `rescue in ' C:/Ruby25/lib/ruby/gems/2.5.0/gems/sqlite3-1.3.13-x64-mingw32/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (LoadError)

后来我又找了针对上面错误的解决方案

修改Gemfile文件
gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
然后运行命令
bundle install
安装完成后
rails s
这回服务运行成功。

在昨天遇到这个问题时,我尝试了第一个方案,结果遇到第二个问题,在找解决方案的时候,有人曾经重新安装了ruby、rails、还有sqlite3,结果就好用了,但是我尝试了他的方法,用了好长时间安装,还是不好用,可能是我机器的有些环境跟他配置的不同。今天重新从第一个问题开始解决,针对问题找解决方案,一下下的排查,没想到这么快就解决了,将这个方法记录下来,让遇到跟我类似问题的少走弯路。

你可能感兴趣的:(railse 专案运行时错误:can't activate sqlite3 (~> 1.3.6))