123

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.

BryanH
  • 5,826
  • 3
  • 34
  • 47
Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129

11 Answers11

397

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.

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
Hawz
  • 4,027
  • 1
  • 10
  • 11
43

Reinstalling my Ruby version seems to have fixed it:

rvm reinstall 2.3.7
Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
  • 12
    This is the answer, if you used rvm to install ruby. If your ruby version is compiled against a version of readline that no longer exists on your system, then you should recompile ruby to link against the new version. I just ran into this issue myself, and tried everything but symlinking readline.8.dylib to stand in for readline.7.dylib (which seems like a really bad idea, even if it seems to have worked for most everyone, upvoting that answer.) – Kingdon Feb 27 '19 at 19:16
  • 4
    I use rbenv and an `rbenv install 2.5.1` worked for me in my context. This went sideways on be after I had run `sudo xcode-select -s /Library/Developer/CommandLineTools` to fix an issue I was experiencing elsewhere. fwiw – somedirection Apr 24 '19 at 14:01
  • 1
    If you're using bundler you might subsequently find that you need to `bundle install` to reinstall the gems with native extensions. – spume May 15 '19 at 13:20
41

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.

ericshao
  • 411
  • 4
  • 2
19

Yes, the best answer is to reinstall.

You can get the version easily by typing:

ruby -v

With rbenv, the command is i.e.:

rbenv install 2.3.7

with rvm:

rvm reinstall 2.3.7
FreePender
  • 4,770
  • 2
  • 18
  • 15
  • Running `rbenv install ` failed with ["rake" from rake conflicts with installed executable from redis-rack](https://github.com/redis-store/redis-rack/pull/34) conflict. I had to run `rbenv uninstall && rbenv install ` – Hirurg103 Dec 12 '19 at 16:22
  • Fixed my problem as well in osx. – cool_php Jul 14 '21 at 14:23
12

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.

Bret Weinraub
  • 1,943
  • 15
  • 21
  • 1
    That's a really great solution if you have several projects running that need different versions of Ruby which cause conflicts in the native lib versions. Cool! – MDickten Apr 04 '23 at 10:16
5

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.

Frederik Spang
  • 3,379
  • 1
  • 25
  • 43
  • Ack! Pristine didn't fix it either. How precisely should I reinstall PostgreSQL without breaking any connection to my current DB? (of course the answer could be "that's not a concern", as far as I know about anything). – Jonathan Tuzman Jan 21 '19 at 15:15
  • The problem is actually finding out which gem is the culprit. I've been able to fix the problem with a symlink, but this solution feels like an unsafe emergency fix to me. How can I find out which gem uses readline.dylib? – MDickten May 11 '22 at 08:30
4

Got this issue:

dyld: Library not loaded: /usr/local/opt/mpfr/lib/libmpfr.4.dylib

doing...

cd /usr/local/opt/mpfr/lib/
ln -s libmpfr.dylib libmpfr.4.dylib

did the trick for me for macOS Catalina

Aris
  • 102
  • 3
3

Background: This has happened when I tried to install tig, but I think this is a common issue that you may have that you need to manually link the installed software into the right path that another software wants.

If you can not find readline installed on your Mac, you should run

brew install readline

After you installed deadline, brew will ask you to link it. But actually you can not link by running

brew link readline

Even you can not link by running

sudo brew link readline

Mac OS will warn you this is extremely dangerous and stop you to do.

The Latest version of readline is version 8, so you will see the error message like

Library not loaded: /usr/local/opt/readline/lib/libreadline.8.dylib

The brew installed deadline at

/usr/local/Cellar/readline/8.0.4

So you have to manually link it to the place that your software wants by using command ls

ln -s /usr/local/Cellar/readline/8.0.4 /usr/local/opt/readline

Enjoy!

Eric Wu
  • 766
  • 6
  • 10
2

So Ive checked a few answers here but I dont think they can work with a vanilla Mojave mac install. Im using 10.14.4 while I did these:

  • get homebrew from https://brew.sh

  • $ brew install coreutils : this installs the gnu coreutils pkg for mac, we want the greadlink from this because macOSX's readlink is not the same as the gnu readlink. Its extremely confusing but such is the life in macland.

  • $ echo 'alias readlink=greadlink' >> ~/.bash_aliases I found macs readlink to be a bit lacking so I overrode the existing readlink by aliasing greadlink. (you can make this usable by all users by $ alias readlink=greadlink >> /etc/bashrc which will enable every user to be able to use it.

  • $ ln -s /usr/local/opt/readline/lib/libreadline.8.dylib /usr/local/opt/readline/lib/libreadline.7.dylib I linked the already linked .8. file instead of '.8.0.' file because if it were to get updated to .8.1. then my readlink wont break or miss features on the library. Im pretty sure we will format our macs before 9+ comes out.

Salyangoz
  • 287
  • 2
  • 14
0

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.

codenamev
  • 2,203
  • 18
  • 24
  • 1
    This only worked after manually symlinking `libreadline.8.dylib` to `libreadline.7.dylib` which was missing. i.e. run command: `ln -s /usr/local/opt/readline/lib/libreadline.8.dylib /usr/local/opt/readline/lib/libreadline.7.dylib` – David Schumann Sep 18 '19 at 15:11
0

My problem was just the same when running lftp.

Just running brew upgrade has solved my problem, as it has updated (among others):

readline 8.0.0_1 -> 8.0.1
lftp 4.8.4 -> 4.8.4_2