Linux Ruby 1.9.2 和 Rails 3 无法打开 rails 控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4922700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby 1.9.2 and Rails 3 cannot open rails console
提问by gkaykck
[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>'
I have installed rails 3 on ruby 1.9.2p136, which is ok i guess. But i cannot start rails console and it gives me the error i copied. The apps worked great with ruby 1.8.7 and i never saw an error like this.
我已经在 ruby 1.9.2p136 上安装了 rails 3,我想这没问题。但是我无法启动 rails 控制台,它给了我我复制的错误。这些应用程序在 ruby 1.8.7 上运行良好,我从未见过这样的错误。
Any ideas what it could be?
任何想法可能是什么?
采纳答案by winfred
Apparently ubuntu and ruby don't always catch dependencies like they should.
显然 ubuntu 和 ruby 并不总是像它们应该的那样捕获依赖项。
From the first google hit(yeah, I clicked on this stack-overflow in place #2 before checking out the first result.)
从第一个谷歌点击开始(是的,我在查看第一个结果之前点击了这个堆栈溢出#2。)
Navigate to the Ruby source and enter:
导航到 Ruby 源代码并输入:
sudo apt-get install libreadline5-dev
cd ext/readline
ruby extconf.rb
make
sudo make install
So, if you're on another distro, make sure you install readline somehow (source/package), then run make/install on extconf from the source. I tried what gkaykck suggested of course but got this without readline already on my system.
因此,如果您使用的是另一个发行版,请确保以某种方式安装 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
回答by futuremint
I'd recommend using rvm (Ruby Version Manager)to manage your different versions of Ruby and switch between them. It does a pretty good job of compiling the various versions for you too. You can even create per-directory .rvmrc files to tell rvm what version of ruby to use in which directory (as well as use per-project gem sets if you want!)
我建议使用rvm(Ruby 版本管理器)来管理不同版本的 Ruby 并在它们之间切换。它在为您编译各种版本方面也做得很好。您甚至可以创建每个目录的 .rvmrc 文件来告诉 rvm 在哪个目录中使用哪个版本的 ruby(如果需要,还可以使用每个项目的 gem 集!)
回答by gkaykck
Solution is to go to the source folder you compiled ruby => ext => readlinethan
解决办法是去你编译的源文件夹ruby => ext => readline比
ruby extconf.rb
make
sudo make install
回答by Nikolay Moskvin
Recipe for those who use rvm:
给那些使用 rvm 的人的食谱:
rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr
In more details about it on https://rvm.io/packages/readline/
有关它的更多详细信息,请访问https://rvm.io/packages/readline/
回答by pisaruk
First of all uninstall every ruby version you have.
首先卸载您拥有的每个 ruby 版本。
After that display rvm requirements:
之后显示 rvm 要求:
rvm requirements
You will get something like:
你会得到类似的东西:
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
Install all dependencies via apt-get.
After that install ruby 1.8.7. This version is required if you plan to use ruby 1.9.x
Now you can install ruby 1.9.3:
通过 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
Note that you dont even need to install readline package via rvm if you had installed it using apt-get.
请注意,如果您使用 apt-get 安装了 readline 软件包,则您甚至不需要通过 rvm 安装它。
回答by superluminary
If you're using RVM you can re-make readline. This fixed the issue for me. Instructions here:
如果您使用的是 RVM,则可以重新制作 readline。这为我解决了这个问题。这里的说明:
回答by Philip
If you want another solution to this problem do this.
如果您想要此问题的另一种解决方案,请执行此操作。
sudo apt-get install libreadline6
Then in your gem file add:
然后在您的 gem 文件中添加:
gem 'rb-readline'
Then
然后
bundle install
And you should be all set.
你应该准备好了。
回答by user2209623
use rvm remove to remove all ruby installed. do a "which ruby" if you still get something, you need to reinstall rvm then install ruby using rvm.
使用 rvm remove 删除所有安装的 ruby。做一个“which ruby”如果你仍然得到一些东西,你需要重新安装rvm然后使用rvm安装ruby。
回答by nikc
With CentOS 6:
使用 CentOS 6:
Remember we are working from the ruby install dir, for me it was:
/opt/ruby-1.9.3-p194/ext/readline
记住我们是从 ruby 安装目录工作的,对我来说是:
/opt/ruby-1.9.3-p194/ext/readline
If you see the following output, then readline is not installed:
如果您看到以下输出,则表示未安装 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
To install with RPM:
使用 RPM 安装:
yum install readline-devel
Then build it:
然后构建它:
ruby extconf.rb
make
sudo make install
回答by Steven Luong C
Adding in the Gemfile
在 Gemfile 中添加
gem 'rb-readline'
and then bundle install
进而 bundle install
did the trick for me
对我有用