Ruby 1.9.2和Rails 3无法打开rails控制台

时间:2011-02-07 14:57:59

标签: ruby-on-rails ruby linux ruby-on-rails-3 rubygems

[gkaykck@main myApplication]$ rails console
/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:6:in `require'
    from script/rails:6:in `<main>'

我已经在ruby 1.9.2p136上安装了rails 3,我猜这是好的。但我无法启动rails控制台,它给了我复制的错误。应用程序与ruby 1.8.7配合得很好,我从来没有看到过这样的错误。

任何想法可能是什么?

10 个答案:

答案 0 :(得分:49)

显然ubuntu和ruby并不总是像他们应该那样捕获依赖关系。

来自first google hit(是的,我在点击第一个结果之前点击了这个堆栈溢出#2)。

导航到Ruby源并输入:

sudo apt-get install libreadline5-dev
cd ext/readline
ruby extconf.rb
make
sudo make install

所以,如果你在另一个发行版上,请确保以某种方式安装readline(源/包),然后从源代码在extconf上运行make / install。我尝试了gkaykck当然建议的但是在我的系统上已经没有readline了。

$ ruby extconf.rb
checking for tgetnum() in -lncurses... no
checking for tgetnum() in -ltermcap... no
checking for tgetnum() in -lcurses... no
checking for readline/readline.h... no
checking for editline/readline.h... no

答案 1 :(得分:29)

使用rvm的人的食谱:

rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr

有关https://rvm.io/packages/readline/

的详细信息

答案 2 :(得分:11)

如果您想要解决此问题,请执行此操作。

sudo apt-get install libreadline6

然后在你的gem文件中添加:

gem 'rb-readline'

然后

bundle install

你应该全力以赴。

答案 3 :(得分:5)

我建议使用rvm (Ruby Version Manager)来管理不同版本的Ruby并在它们之间切换。它也可以很好地为您编译各种版本。你甚至可以创建每个目录的.rvmrc文件来告诉rvm在哪个目录中使用什么版本的ruby(如果你想要的话,也可以使用每个项目的gem集!)

答案 4 :(得分:5)

首先卸载你拥有的每个ruby版本。

之后显示rvm要求:

rvm requirements

你会得到类似的东西:

Requirements for Linux ( DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu 11.10" )

NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)   
This is the *original* / standard Ruby Language Interpreter  
      'ree'  represents Ruby Enterprise Edition  
      'rbx'  represents Rubinius  

bash >= 4.1 required curl is required git is required (>= 1.7 for
ruby-head) patch is required (for 1.8 rubies and some ruby-head's).

To install rbx and/or Ruby 1.9 head (MRI) (eg. 1.9.2-head), then you
must install and use rvm 1.8.7 first.

Additional Dependencies: 
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
  ruby: /usr/bin/apt-get install build-essential openssl libreadline6 
  libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev 
  libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev 
  ncurses-dev automake libtool bison subversion

# For JRuby, install the following:
  jruby: /usr/bin/apt-get install curl g++ openjdk-6-jre-headless
  jruby-head: /usr/bin/apt-get install ant openjdk-6-jdk

# For IronRuby, install the following:
  ironruby: /usr/bin/apt-get install curl mono-2.0-devel

通过apt-get安装所有依赖项。
之后安装ruby 1.8.7。如果您打算使用ruby 1.9.x
,则需要此版本 现在你可以安装ruby 1.9.3:

rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr

请注意,如果您使用apt-get安装了readline软件包,则甚至不需要通过rvm安装readline软件包。

答案 5 :(得分:3)

使用CentOS 6:

  

请记住,我们正在使用ruby install目录,对我而言:

   /opt/ruby-1.9.3-p194/ext/readline

如果看到以下输出,则表示未安装readline:

$ ruby extconf.rb 
checking for tgetnum() in -lncurses... no
checking for tgetnum() in -ltermcap... no
checking for tgetnum() in -lcurses... no
checking for readline/readline.h... no
checking for editline/readline.h... no

使用RPM安装:

yum install readline-devel

然后建立它:

ruby extconf.rb 
make
sudo make install

答案 6 :(得分:1)

解决方法是转到您编译的源文件夹 ruby​​ =&gt; ext =&gt; readline 而不是

ruby extconf.rb
make
sudo make install

答案 7 :(得分:1)

添加Gemfile

gem 'rb-readline'

然后bundle install

为我做了伎俩

答案 8 :(得分:0)

如果您正在使用RVM,则可以重新制作readline。这为我解决了这个问题。说明:

no such file to load -- readline (Load Error)

答案 9 :(得分:0)

使用rvm remove删除所有安装的ruby。 做一个“哪个红宝石”,如果你还有东西,你需要重新安装rvm然后使用rvm安装ruby。