rails server 错误

Error: /opt/homebrew/Cellar/ruby/3.4.7/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require': linked to incompatible
/Users/sihic/.rbenv/versions/3.4.7/lib/libruby.3.4.dylib -
/Users/sihic/sites/haas/vendor/bundle/ruby/3.4.0/gems/msgpack-1.8.0/lib/msgpack/msgpack.bundle (LoadError)
from /opt/homebrew/Cellar/ruby/3.4.7/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
from /Users/sihic/sites/haas/vendor/bundle/ruby/3.4.0/gems/msgpack-1.8.0/lib/msgpack.rb:7:in ''
from /opt/homebrew/Cellar/ruby/3.4.7/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
from /opt/homebrew/Cellar/ruby/3.4.7/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
from /Users/sihic/sites/haas/vendor/bundle/ruby/3.4.0/gems/bootsnap-1.18.6/lib/bootsnap/load_path_cache/store.rb:5:in 'block in '
from /Users/sihic/sites/haas/vendor/bundle/ruby/3.4.0/gems/bootsnap-1.18.6/lib/bootsnap/explicit_require.rb:50:in
'Bootsnap::ExplicitRequire.with_gems'
from /Users/sihic/sites/haas/vendor/bundle/ruby/3.4.0/gems/bootsnap-1.18.6/lib/bootsnap/load_path_cache/store.rb:5:in ''
from /Users/sihic/sites/haas/vendor/bundle/ruby/3.4.0/gems/bootsnap-1.18.6/lib/bootsnap/load_path_cache.rb:77:in 'Kernel#require_relative'
from /Users/sihic/sites/haas/vendor/bundle/ruby/3.4.0/gems/bootsnap-1.18.6/lib/bootsnap/load_path_cache.rb:77:in ''


太好了!Rails 服务器现在成功启动了!

问题已解决

错误的原因是 gem 的原生扩展被链接到了错误的 Ruby 动态库(Homebrew 的而不是 rbenv 的)。

解决方案:
使用 bundle exec rails s 而不是 rails s 来启动服务器。

Rails 服务器现在正在运行:
– 地址:http://127.0.0.1:3000
– Ruby 版本:3.4.7 (rbenv)
– Puma 版本:7.1.0
– Rails 版本:8.0.3

你可以在浏览器中访问 http://localhost:3000 来查看你的应用。使用 Ctrl-C 停止服务器。

建议: 今后总是使用 bundle exec rails 命令来确保使用正确的 gem 环境,或者你可以考虑使用 bin/rails s 作为替代。