rails中可以用使用console命令行来测试运行rails应用程序,但是采用源码编译安装的话可能缺少readline动态库,导致ruby无法使用这个库此时如果调用rails console(rails 3中)会出现以下错误:
- /usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `require': no such file to load -- readline (LoadError)
- from /usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
- from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `require'
- from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `<top (required)>'
- from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `require'
- from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `<top (required)>'
- from script/rails:10:in `require'
- from script/rails:10:in `<main>'
在我的ubuntu 10.4系统中。系统会安装libreadline6这个库,但是缺少libreadline6-dev这个开发库,所以ruby在编译安装的时候无法生成readline这个动态库。此时在ubuntu中用命令:
- sudo apt-get install libreadline6-dev或者sudo apt-get install libreadline-dev
这两个命令都会安装libreadline6-dev开发库。安装完后在ruby源码ext/readline目录中,我的是/usr/local/src/ruby-1.9.2-p0/ext/readline下执行:
- sudo ruby extconf.rb
- sudo make
- sudo make install
执行这些命令后,会重新编译安装readline动态库,此时问题便会得到解决。