Library not loaded: /usr/local/opt/readline/lib/li

2020-05-11 10:53发布

When I try running rails console I get this error:

/Users/TuzsNewMacBook/.rvm/gems/ruby-2.3.7/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require':
 dlopen(/Users/TuzsNewMacBook/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/x86_64-darwin18/readline.bundle, 9): 
Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)

A quick search got me to this post and I've tried a few things:

brew reinstall postgresql (this is indeed the DB for this project)

and

cd /usr/local/opt/readline/lib    
ln libreadline.8.0.dylib libreadline.6.2.dylib

(my version of readline is 8)

and brew link readline --force

But none of these have fixed it.

I recently added pry-coolline, guard and guard-livereload gems to my project if that makes any difference (rails console loaded fine before those). I'm running on the latest macos.

(Update) I’m using pry rails as my rails console, if that makes any difference.

Any help? Thanks.

10条回答
趁早两清
2楼-- · 2020-05-11 11:30

Most often in Ruby-applications, this is caused by gems that have extensions (the gems saying "Building native extensions.."), that are built using a specific version of, in this case, readline.

Basically, there are two solutions:

Either, you can symlink version 8 of the gem, to the version missing. This will work in many cases, but if backwards compatibility is broken, it will not.

Or, if the gem actually supports version 8, you can reinstall that specific gem, or "pristine" it by running gem pristine --all.

EDIT: In scope of your "what I've tried", reinstalling PostgreSQL, is also one of the binaries, built using a specific version, that may also require a rebuild, to work with a system library, such as readline.

查看更多
一纸荒年 Trace。
3楼-- · 2020-05-11 11:33

can you try

cd /usr/local/opt/readline/lib    
ln -s libreadline.8.dylib libreadline.7.dylib

you are on the right track but it seems like rails is looking for libreadline.7.dylib and libreadline.7.dylib is not there in the folder.

查看更多
Animai°情兽
4楼-- · 2020-05-11 11:40

A very simple solution that doesn't involve rebuilding your RVM gemset OR sym-linking libraries.

Add to your Gemfile:

gem 'rb-readline'

If you are doing bundler groups

group :development do
  gem 'rb-readline'
end

Then run

> bundle

Let me know if that doesn't work.

查看更多
\"骚年 ilove
5楼-- · 2020-05-11 11:41

the error seems to be thrown when searching for /usr/local/opt/readline/lib/libreadline.7.dylib.

Have you tried to symlink that?

So something like:

cd /usr/local/opt/readline/lib 
ln -s libreadline.8.0.dylib libreadline.7.dylib

Just tried that on macOS Mojave, ruby 2.5.3p105 and Rails 5.2.2 and worked.

查看更多
在下西门庆
6楼-- · 2020-05-11 11:41

I would recommend against manually symlink'ing native libraries. Aas of OS X 10.4, the standard include library path /usr/include is no longer used and is locked by SIP (making it difficult to move things to).

Apple ships a “legacy installer” for you to be able to install the headers in the “old location”, which will also resolve your path to correctly find headers installed via brew.

cp /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg ~/Desktop && open ~/Desktop/macOS_SDK_headers_for_macOS_10.14.pkg`

See here for a detailed write-up on what is going on.

查看更多
乱世女痞
7楼-- · 2020-05-11 11:44

Reinstalling my Ruby version seems to have fixed it:

rvm reinstall 2.3.7
查看更多
登录 后发表回答