为什么Rails控制台会显示“无法加载文件--readline”?

6

我刚接触Ruby on Rails,并使用RVM来管理Ruby版本。

我的笔记本电脑已安装Ruby1.8.7,但我的项目使用RVM,Ruby1.9.3和Rails 3.2.11。

如果我运行rails crails console,就会出现以下错误:

/home/phil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError)
from /home/phil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands/console.rb:3:in `require'
from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands/console.rb:3:in `<top (required)>'
from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands.rb:38:in `require'
from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands.rb:38:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

你正在运行哪个 rails 命令?which rails 的输出是什么? - Stuart M
感谢 Stuart 的回复。我已经回答了如下内容。 - polarcare
1个回答

11

编译Ruby时需要安装readline库。

如果您使用的是CentOS/Redhat/Fedora Linux系统,请执行以下命令来安装该软件包:

sudo yum install readline-devel

或者,在Ubuntu上使用:

sudo apt-get install libreadline6 libreadline6-dev

然后重新编译Ruby。


感谢Stuart和John的回复。我运行了“rvm use 1.9.3”,它返回“ruby 1.9.3p392 (2013-02-22 revision 39386) [i686-linux]”。一切都正常,只有当我运行“rails c”或“rails console”时才会出现上述错误。我运行了“sudo apt-get install libreadline6 libreadline6-dev”并安装了它们,但不幸的是我仍然得到这个错误。 - polarcare
johnkoht - 当你说“然后重新编译Ruby”,你具体指的是什么? - polarcare
然后使用“rvm卸载[RUBYVERSION]”和“rvm安装[RUBYVERSION]”重新编译ruby。现在它可以工作了,万分感谢johnkoht,你太棒了! - polarcare
很高兴你把它搞定了(抱歉直到现在我才看到你的其他消息)。 - johnkoht

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接