我在创建新的 Rails 项目时遇到了麻烦。当我运行rails new project_name
它时rails webpacker:install
,它失败并出现以下错误:
LoadError: libffi.so.8: cannot open shared object file: No such file or directory - /home/matija/.asdf/installs/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/ffi-1.15.4/lib/ffi_c.so
/home/matija/Documents/learning-rails/course-project/config/application.rb:7:in `<main>'
/home/matija/Documents/learning-rails/course-project/Rakefile:4:in `<main>'
/home/matija/Documents/learning-rails/course-project/bin/rails:5:in `<top (required)>'
<internal:/home/matija/.asdf/installs/ruby/3.0.2/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:/home/matija/.asdf/installs/ruby/3.0.2/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
/home/matija/Documents/learning-rails/course-project/bin/spring:10:in `block in <top (required)>'
<internal:kernel>:90:in `tap'
/home/matija/Documents/learning-rails/course-project/bin/spring:7:in `<top (required)>'
bin/rails:2:in `load'
bin/rails:2:in `<main>'
Caused by:
LoadError: cannot load such file -- 3.0/ffi_c
/home/matija/Documents/learning-rails/course-project/config/application.rb:7:in `<main>'
/home/matija/Documents/learning-rails/course-project/Rakefile:4:in `<main>'
/home/matija/Documents/learning-rails/course-project/bin/rails:5:in `<top (required)>'
<internal:/home/matija/.asdf/installs/ruby/3.0.2/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
<internal:/home/matija/.asdf/installs/ruby/3.0.2/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
/home/matija/Documents/learning-rails/course-project/bin/spring:10:in `block in <top (required)>'
<internal:kernel>:90:in `tap'
/home/matija/Documents/learning-rails/course-project/bin/spring:7:in `<top (required)>'
bin/rails:2:in `load'
bin/rails:2:in `<main>'
(See full trace by running task with --trace)
我正在使用 ASDF 进行 ruby 版本管理。
我尝试了许多解决方案,例如卸载和安装 gem、运行gem pristine
以及 SO 和这里提供的一些其他方法。
答案1
答案2
当我在处理 Rails 项目时,我意识到系统版本和项目版本之间存在差异,因此我的解决方案是通过运行以下命令来匹配两者:
gem uninstall ffi
gem install ffi -v 1.15.0 -- --disable-system-libffi