---
title: "ruby 1.9 irb rails console不能用readline问题"
author: "夜鸣猪"
date: "2011-11-24T02:49:17Z"
tags: ["Ruby", "readline"]
categories: ["编程语言"]
slug: "ruby-1-9-irb-rails-console-readline"
draft: false
lastmod: "2012-03-28T07:50:25Z"
id: 1275517
url: "https://hlee.iteye.com/blog/1275517"
---

<span style="color:darkred">Update: 2012/03/27</span>
当前版本ruby1.9.3p135
ubuntu 11.10

解决办法先试试

```ruby
rvm requirements
#先安装依赖的包
rvm remove 1.9.2
rvm install 1.9.2

```

遇到问题是rvm use用不了，其他都能用，提示

> RVM is not a function, selecting rubies with 'rvm use ...' will not work.

是一个所谓的“Run as login shell”问题，官方有介绍<https://rvm.beginrescueend.com/integration/gnome-terminal/>
实际设计多用户登录什么的问题，就是把如下放到.bashrc,不要放到其他什么bash_profile

```ruby

[[ -s "$home/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

```


```ruby

source ~/.bashrc

```

问题现象就是


> 
> Readline was unable to be required, if you need completion or history install readline then reinstall the ruby.
> You may follow 'rvm notes' for dependencies and/or read the docs page https://rvm.beginrescueend.com/packages/readline/ . Be sure you 'rvm remove X ; rvm install X' to re-compile your ruby with readline support after obtaining the readline libraries.
> 
> 


标准的解决办法是
<https://rvm.beginrescueend.com/packages/readline/>

问题是我一进行到这一步就有问题

```ruby

$ cd $HOME/.rvm/src/ruby-1.9.2-p0/ext/readline
$ ruby extconf.rb -- --with-readline-dir="$HOME/.rvm/usr"

```



> checking for tgetnum() in -lncurses... yes
> checking for readline/readline.h... yes
> checking for readline/history.h... yes
> checking for readline() in -lreadline... no
> 


后来发现两个问题：
1. 路径

```ruby

ruby extconf.rb -- --with-readline-dir='/home/ra/.rvm/usr/include/readline'

```


一个是没有装

```ruby

sudo aptitude install libreadline-dev
sudo aptitude install libreadline5-dev libncurses5-dev

```

够新的呢要换6

```ruby

sudo aptitude install libreadline6-dev 

```


1.9.3参考

```ruby

rvm pkg install openssl #older format - rvm package install openssl
rvm pkg install iconv #older format - rvm package install iconv
rvm pkg install readline#rails console缺少的lib
rvm remove 1.9.3
rvm install 1.9.3 -C --with-openssl-dir=\$HOME/.rvm/usr,--with-iconv-dir=\$HOME/.rvm/usr, --with-readline-6.2-dir=\$HOME/.rvm/usr 
rvm 1.9.3 --default

```


还是ubuntu的readline error


> undefined symbol: UP


```shell

ls /usr/local/lib

su
mkdir temp
mv /usr/local/lib/libreadline* temp
ldconfig
apt-get update

rm -rf /usr/local/lib/temp

```