$ rails c ~/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': dlopen(~/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/pg-1.4.3/lib/pg_ext.bundle, 0x0009): Library not loaded: '/usr/local/opt/postgresql/lib/libpq.5.dylib' Referenced from: '~/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.bundle' Reason: tried: '/usr/local/opt/postgresql/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file), '/usr/local/Cellar/[email protected]/14.5_1/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file) - ~/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/pg-1.4.3/lib/pg_ext.bundle (LoadError) ...
尝试再次安装 pg gem
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$ gem install pg
Fetching pg-1.4.3.gem Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. .... To see why this extension failed to compile, please check the mkmf.log which can be found here:
Gem files will remain installed in ~/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/gems/pg-1.4.3 for inspection. Results logged to ~/.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-20/3.0.0/pg-1.4.3/gem_make.out
根据错误提示检查 mkmf.log 日志文件
# ~.asdf/installs/ruby/3.0.0/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-20/3.0.0/pg-1.4.3/mkmf.log You have not agreed to the Xcode license agreements, please run 'sudo xcodebuild -license' from within a Terminal window to review and agree to the Xcode license agreements.