Review your favorite Linux distribution.
Go Back > Blogs > omgiamlinux
User Name


Rate this Entry

Day 6 - Installing Rails, gem, rvm, etc.

Posted 10-27-2011 at 04:53 PM by omgiamlinux
Updated 10-27-2011 at 06:32 PM by omgiamlinux

This post is a part of a mini-series!
Day 6
1) Installing (You Are Here)
2) Test a Rails App! link
3) Configuring Webserver link
4) Configuring MySql link

:: Installing Ruby

Install prerequisites so we can use curl and download rvm (Ruby Version Manager).
$  apt-get update
$  apt-get install build-essential git-core curl
Install remaining important stuff...
$  apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf

Download and install rvm (not using apt-get obviously)
$  bash < <(curl -s
Then, sort of put rvm into the environment PATH (this won't work if you used 'su', and rvm may only be available if you're logged in through SSH. You also need to log out and log back in...)

(Run the below code as the desired user and it will put stuff at the bottom of ~/.bashrc)
$  echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
(Run as root and it should end up in /root/.bashrc)
$  echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
Then you could try to run this command or if that doesn't work, restart your ssh session (I don't get linux...)
$  . ~/.bashrc
If your installation is successful, typing [inline]$ rvm [/inline] will yield a result.

One more configuration is needed for rvm to work properly:
$  rvm pkg install zlib
Now install a few versions of ruby:
$  rvm install 1.8.7
$  rvm install 1.9.2
Weeks later, update rvm and ruby 1.9.2 to the latest patch!
$  rvm get latest   # this will update rvm itself
$  rvm reload
$  rvm install 1.9.2
Switch to using a specific version of ruby, and set the default version to be used at login (necessary).
$  rvm use 1.9.2
$  rvm --default use 1.9.2
Trouble Shooting:
At this point you should be able to type [inline]$ gem list[/inline] and see that the gem 'rake' is installed. If not, then you need to uninstall those versions of ruby, install zlib manuallish, and reinstall (
$  rvm remove 1.9.2
$  rvm remove 1.8.7
$  rvm pkg install zlib
$  rvm install 1.9.2
$  rvm install 1.8.7

Sometimes you'll have instances where 1.9.2 will be incompatible with some rails thing you're trying to do. In that case, switch your ruby version down to 1.8.7.
$  rvm --default use 1.8.7

Getting RVM working in x11(linux GUI)
RVM should work just fine over ssh at this point. But to make it so RVM will work in your x11 session (linux GUI) too, you must modify the default "profile" for terminal windows.

1) Spawn a terminal window
Applications ---> 'Accessories' ---> 'Terminal'

2) Edit the default terminal profile to work with RVM

Edit ---> Profiles... --> SELECT "Default" --> CLICK "Edit"

"Title and Command" --> CHECK "Run command as a login shell"

That will make all terminals work with rvm EXCEPT for root terminals.

:: Installing Gem and Gemsets

When we installed rvm, it automatically installed gem for us (version 1.6.2 for me). Check this site out for details on gemsets and using rvm to manage gem.

This rvm program is so cool that it lets us have many, compartmentalized 'gemsets' for each ruby version you have installed. Let's create an alternative gemset for ruby 1.8.7 (which we're already set to because our last version change command was [inline] rvm --default use 1.8.7[/inline]

$  rvm gemset create testrails2.3.5
$  rvm 1.8.7@testrails2.3.5
$  rvm gemset list
$  rvm gemset list
$  rvm gemset list_all
Now if we really wanted to, we could install rails version 2.3.5 and test it here inside 1.8.7, while still having the latest version of rails in the head 1.9.2 version with out any confusion over which rails app will be used. Let's switch back to the main 1.9.2 version since we don't want to do anything with gems yet.
$  rvm 1.9.2
Here's an interesting trick where you put a .rvmrc file in some directory and it will automatically setup your rvm to be using the version you specified.
$  echo "rvm 1.9.2" > APPNAME/.rvmrc

To update gem using rvm:
$  rvm rubygems 1.8.5
For me, it gave me a dumb warning and so I had to run the command a second time...

For a standalone installation of gem, you'd see this command, but usually you can get away with using rvm to update it for you:
$  gem update --system
You can downgrade too, if gems are giving you tons of warnings and not working:
$  gem update --system 1.7.2

:: Installing Rails

Apparently, if you use apt-get to install gem, the name of gem changes depending on what version it is atm... Luckily this new procedure I wrote avoids this problem.
$  gem install rails --include-dependencies
INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
<randomly hit enter once?>
<randomly hit enter again>
<randomly hit enter again?>
<wait a long time for it to start updating you with progress reports on its downloads...>
OK, this step is weird. If you're lucky, it will work. If you're unlucky, you'll need to try it again. Don't ask me how. Just try again if it doesn't do anything for half an hour or something... My test machine sux.

Also, what if you want to install another version of rails in addition to the latest and greatest?
$  gem install rails -v=2.3.5
Easy enough.

:: Configure MySQL with rails
Since we already installed MySql in a prior entry, we just need to install the mysql adapter gems.
(When I found a reference, it said do libmysqlclient14-dev, but it was out of date by 1 I guess...)
$  apt-get install libmysqlclient15-dev   
$  gem install mysql
$  gem install mysql2      ~~that might be important too...
(ref (borrowed a single command):

$  cd /var/rails
$  rails new myapp
zomg, we did it! We can even test it out on WEBrick, the built in server!

$  cd myapp
$  rails server
Want to make webrick faster?
You can make webrick more responsive on remote machines by following this:
I found my webrick config file at:

Make true the line [inline]oNotReverseLookup => nil, [/inline]


Oh crap... At some point, I broke my nginx server. It now thinks its root is:
It used to think it was /usr/local/nginx/html
This is not good...

Ok, looks like, according to this file not found message, "Apache/2.2.16 (Debian) Server at Port 80"
I inadvertently installed apache...
I was wondering why /var/www was all setup for me already.
I wonder when this happened?
I better check my history

...Jeez... I don't see it in there... I wonder if I'm sploited somehow?

whereis apache and apache2 finds it

Ok, I manually uninstalled every trace of dnsmasq and apache2 by doing
whereis dnsmasq
and using rm -rf on everything that popped up.


(you might need some of this still too. Some we installed previously, but w/e.)
$  apt-get install -y libdbd-sqlite3-ruby sqlite3 libsqlite3-dev libsqlite3-ruby
$  gem install sqlite3-ruby

Let's close this entry up with a hello world in ruby on the command line (this is not 'rails' it's just ruby).
(vi hello.rb)
# this is a super cool hello world example
puts "hello world"
puts "!" * 5
puts 1 
puts "!" * 3

to run that ruby script, type
$  ruby hello.rb
You may go to the next entry on rails if you'd like.
Views 617 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 11:42 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration