Several times I’ve found out that my rails console didn’t work, not really sure why but I guess that is when there is a certain update in the Ubuntu. The versions of the software are ruby 1.9.3, rails 3.2.8 and rvm 1.14.11
I’m in my projects directory/folder, in my case that is
sonduk@sonduk:~/reposrails/stress-faktor
remember that while reading this post
So what happens is
$ rails c
/home/sonduk/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError)
from /home/sonduk/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
from /home/sonduk/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:3:in `require'
from /home/sonduk/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:3:in `<top (required)>'
from /home/sonduk/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:38:in `require'
from /home/sonduk/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:38:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
So to making the rails console work again, this is what I’ve done:
Since I’m using rvm, first I check the requirements, with
$ rvm requirements
This shows additional OS specific dependencies/requirements for building various rubies.
The output I get is
Requirements for Linux ( DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04 DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION=”Ubuntu 12.04.1 LTS” )
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-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
Since the requirements suggest installing some software I do so
$ sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
Now, I’ll have to reinstall the rvm
$rvm remove 1.9.3
$rvm install 1.9.3
If you have a different version of rvm you should put yours instead of 1.9.3, to check what version you have,
$rvm -v
To check if it works we need to exit the current project directory and re-enter again
If it doesn’t work, that is what happen to me since it ask me to install rails again
First I checked if rvmrc file existed in the top level of my rails project directory(the specific project not your repos directory or where you have all rails projects), it didn’t so I created it in the project main directory. you can create the file with the text editor that use, like or prefer, in my case I used emacs.
$emacs .rvmrc
then I added one line
rvm use --create 1.9.3@name_of_your_project
This will make rvm to use ruby 1.9.3 for your project
Then we leave the project directory and enter again and it should show a notice like this one
NOTICE =
====================================================================================
= RVM has encountered a new or modified .rvmrc file in the current directory =
= This is a shell script and therefore may contain any shell commands. =
= =
= Examine the contents of this file carefully to be sure the contents are =
= safe before trusting it! ( Choose v[iew] below to view the contents ) =
====================================================================================
Do you wish to trust this .rvmrc file? (/home/sonduk/reposrails/stressFaktor/.rvmrc)
y[es], n[o], v[iew], c[ancel]> yes
Using /home/sonduk/.rvm/gems/ruby-1.9.3-p194 with gemset stressFaktor
Then we run bundle to install all the gems
$ bundle
After checking, installing, compiling you should get a message like this
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
now you should be able to run your rails console 🙂
$ rails c
Loading development environment (Rails 3.2.8)
1.9.3p194 :001 >
and now time to Enjoy! 🙂