10

I have only readline 7 installed and I can't find a single way to install version 6 on macOS Sierra. This is the error when trying to run rails c:

/Users/akashagarwal/.rvm/gems/ruby-2.3.0@global/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require': dlopen(/Users/akashagarwal/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
Referenced from: /Users/akashagarwal/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle Reason: image not found - /Users/akashagarwal/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle

Akash Agarwal
  • 2,326
  • 1
  • 27
  • 57
  • 1
    Did you try reinstalling ruby? I think when you compile ruby you get it with readline support. Your OS updated readline but ruby is still trying to use the old version. – radubogdan Oct 14 '16 at 20:45
  • @radubogdan are you on macOS Sierra? And which ruby version are you on? – Akash Agarwal Oct 14 '16 at 20:49
  • Unfortunately I am not, but all of my coworkers upgraded and they didn't have any problems. Do you use rbenv/rvm or you have the "stock" ruby ? – radubogdan Oct 14 '16 at 20:52
  • @radubogdan rvm, I just stumbled upon rbenv, I guess I should use that instead. I'm currently on this: `ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]`. Is that what you're on? – Akash Agarwal Oct 14 '16 at 20:53
  • I'm using `ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]` but that shouldn't influence anything. Since you have a ruby manager I'd say go crazy and install a new version. I'm pretty sure it will use the new readline dylib to compile. – radubogdan Oct 14 '16 at 20:57
  • 1
    @radubogdan I'm new to ruby because of rails and I'm having a pretty hard time here trying to figure out the latest version of ruby. I did try `rvm install ruby-2.3.1_2` but it couldn't find it. That version is what `brew` installed it for me but still can't use it with rvm I don't understand why. – Akash Agarwal Oct 14 '16 at 21:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/125759/discussion-between-akash-aggarwal-and-radubogdan). – Akash Agarwal Oct 14 '16 at 21:10

4 Answers4

24

I had a similar issue and solved it with:

ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib

source: https://github.com/rails/rails/issues/26658

Will Clarke
  • 3,480
  • 1
  • 16
  • 13
  • 2
    That's a hackish way. You may run into errors which you don't understand. I updated my ruby version using rbenv and hence updated rails as well. Now rails needs the latest readline. – Akash Agarwal Oct 21 '16 at 14:53
8

A better answer that worked well for me:

rbenv install -f 2.2.3 && RBENV_INSTALL=2.2.3 gem pristine --all

Jim Meyer
  • 1,326
  • 1
  • 11
  • 12
2

I had the same error and this worked for me.
Add gem 'rb-readline' in your Gemfile and bundle install

And just type bundle exec rails c

asayamakk
  • 143
  • 2
  • 9
1

Jim Meyer wrote a good answer, but an even better blog post.

Specifically this is what should be done given that you use rbenv and maybe also homebrew to install readline: (cut from Jim's blog post for posterity)

> xcode-select --install
[... popup dialog launches and you do the install dance ...]
> brew update && brew upgrade
[... many package defs update and upgrade ... ]
> for i in `rbenv versions --bare|xargs`; do rbenv install -f $i && RBENV_VERSION=$i gem pristine --all; done
[... much building of ruby and gem native extensions for each installed ruby version ...]
Eliot Sykes
  • 9,616
  • 6
  • 50
  • 64
Stefan Wallin
  • 1,502
  • 1
  • 14
  • 19