rails console --sandbox出现的安装错误解决方案

时间:2021-01-30 19:23:30

rails中可以用使用console命令行来测试运行rails应用程序,但是采用源码编译安装的话可能缺少readline动态库,导致ruby无法使用这个库此时如果调用rails console(rails 3中)会出现以下错误:

  1. /usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `require': no such file to load -- readline (LoadError)
  2. from /usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
  3. from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `require'
  4. from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `<top (required)>'
  5. from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `require'
  6. from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `<top (required)>'
  7. from script/rails:10:in `require'
  8. from script/rails:10:in `<main>'

在我的ubuntu 10.4系统中。系统会安装libreadline6这个库,但是缺少libreadline6-dev这个开发库,所以ruby在编译安装的时候无法生成readline这个动态库。此时在ubuntu中用命令:

  1. 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下执行:

  1. sudo ruby extconf.rb
  2. sudo make
  3. sudo make install

执行这些命令后,会重新编译安装readline动态库,此时问题便会得到解决。