6

I'm using rails3 for the first time (i've been using rails2 for years) inside an rvm. Trying to start the console, i get this error:

require': no such file to load -- readline

I've googled around and this seems to be a common problem. Most solutions seem to involve 1) installing the following: sudo apt-get install libncurses5-dev libreadline5-dev 2) going to the gem folder for readline, running ruby extconf.rb which generates a makefile 3) doing make and make install

Now, i didn't have readline installed in my rvm, so i tried to install it. But couldn't work out what the gem is: gem install readline doesn't give any results. The only one i found was gem install rdp-rb-readline. I installed the two dev libraries, installed the rdp-rb-readline gem, went to the subsequent gem folder, and ran ruby extconf.rb. This did indeed generate a makefile. But i can't make it or make install: i get these errors:

max-laptop:readline$ make cc -I. -I. -I/usr/lib/ruby/1.8/i486-linux -I. -DHAVE_READLINE_READLINE_H -DHAVE_READLINE_HISTORY_H -DHAVE_RL_FILENAME_COMPLETION_FUNCTION -DHAVE_RL_USERNAME_COMPLETION_FUNCTION -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_DEPREP_TERM_FUNCTION -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_BASIC_WORD_BREAK_CHARACTERS -DHAVE_RL_COMPLETER_WORD_BREAK_CHARACTERS -DHAVE_RL_BASIC_QUOTE_CHARACTERS -DHAVE_RL_COMPLETER_QUOTE_CHARACTERS -DHAVE_RL_FILENAME_QUOTE_CHARACTERS -DHAVE_RL_ATTEMPTED_COMPLETION_OVER -DHAVE_RL_LIBRARY_VERSION -DHAVE_RL_EVENT_HOOK -DHAVE_RL_CLEANUP_AFTER_SIGNAL -DHAVE_RL_CLEAR_SIGNALS -DHAVE_RL_VI_EDITING_MODE -DHAVE_RL_EMACS_EDITING_MODE -DHAVE_REPLACE_HISTORY_ENTRY -DHAVE_REMOVE_HISTORY -fPIC -fno-strict-aliasing -g -g -O2 -fPIC -c readline.c readline.c: In function ‘readline_readline’: readline.c:82: error: ‘rb_io_t’ undeclared (first use in this function) readline.c:82: error: (Each undeclared identifier is reported only once readline.c:82: error: for each function it appears in.) readline.c:82: error: ‘ofp’ undeclared (first use in this function) readline.c:82: error: ‘ifp’ undeclared (first use in this function) make: *** [readline.o] Error 1

Kind of stuck now. Am i missing something else fundamental that i need to make the required libraries/gem/whatever?

Grateful for any advice - max

SOLUTION: I actually just solved this - i uninstalled the rdp-rb-readline gem, then did gem install rb-readline, then added gem 'rb-readline' to my app's Gemfile. I guess it just needed to know where to look for the readline stuff if it wasn't in the usual place. I didn't need to do anything with extconf.rb, which is good because the rb-readline gem doesn't have one.

I've left this at the end of my question because a) someone else might have a better understanding of the problem rather than my trial and error approach and b) in case anyone else has the same problem.

Max Williams
  • 32,435
  • 31
  • 130
  • 197

2 Answers2

4

If you're using rvm, you can always make use of the package installer facility to fix any issues your OS may have. Ruby often uses libraries that are a bit different from what you have installed:

rvm package install readline

The rvm installer applies several patches against a specific, known-working version of readline and should build without issues. This readline package won't affect your system install, and is used only for rvm-based builds.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • 1
    Thanks tadman - i just tried that and it seemed to happily go through the installation process. But i still get the same problem. I found another solution, i don't know if that's any better, which i appended to my OP. But i like your approach better and would like to get it working properly. – Max Williams Mar 30 '11 at 14:36
  • As a note, you need to build your `ruby` against the rvm-managed readline for this to work properly using `rvm install`. – tadman Mar 30 '11 at 17:55
  • Sorry tadman, i don't quite understand what you mean. Could you provide more details? Thanks! – Max Williams Mar 31 '11 at 10:57
  • If you install the `readline` package after you've build Ruby, it has no effect. You must rebuild Ruby with the `readline` package installed for it to be linked in properly. – tadman Apr 01 '11 at 15:32
3
cd ~/.rvm/src/ruby-X.X.X-pXXX/ext/readline

(replace ruby-1.9.2-p180 with your system ruby version)

ruby extconf.rb

if any checking says no, install these pakages:

sudo apt-get install libncurses5-dev libreadline5-dev

and run ruby extconf.rb

you should get all checking yes,

make
make install

now it will work.

Sayuj
  • 7,464
  • 13
  • 59
  • 76