LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Blogs > omgiamlinux
User Name
Password

Notices

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
ref: http://ryanbigg.com/2010/12/ubuntu-r...rails-and-you/

Install prerequisites so we can use curl and download rvm (Ruby Version Manager).
Code:
$  apt-get update
$  apt-get install build-essential git-core curl
Install remaining important stuff...
Code:
$  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)
Code:
$  bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
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)
Code:
$  echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc
(Run as root and it should end up in /root/.bashrc)
Code:
$  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...)
Code:
$  . ~/.bashrc
If your installation is successful, typing [inline]$ rvm [/inline] will yield a result.

One more configuration is needed for rvm to work properly:
Code:
$  rvm pkg install zlib
Now install a few versions of ruby:
Code:
$  rvm install 1.8.7
$  rvm install 1.9.2
Weeks later, update rvm and ruby 1.9.2 to the latest patch!
Code:
$  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).
Code:
$  rvm use 1.9.2
$  rvm --default use 1.9.2
[spoiler]
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 (https://rvm.beginrescueend.com/packages/zlib/):
Code:
$  rvm remove 1.9.2
$  rvm remove 1.8.7
$  rvm pkg install zlib
$  rvm install 1.9.2
$  rvm install 1.8.7
[/spoiler]

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.
Code:
$  rvm --default use 1.8.7

Getting RVM working in x11(linux GUI)
[spoiler]
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.
[/spoiler]


:: 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. https://rvm.beginrescueend.com/gemsets/basics/

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]

Code:
$  rvm gemset create testrails2.3.5
$  rvm 1.8.7@testrails2.3.5
$  rvm gemset list
list:
Code:
$  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.
Code:
$  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.
Code:
$  echo "rvm 1.9.2" > APPNAME/.rvmrc

To update gem using rvm:
Code:
$  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:
Code:
$  gem update --system
You can downgrade too, if gems are giving you tons of warnings and not working:
Code:
$  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.
Code:
$  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?
Code:
$  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...)
Code:
$  apt-get install libmysqlclient15-dev   
$  gem install mysql
$  gem install mysql2      ~~that might be important too...
(ref (borrowed a single command): http://daniel.lorch.cc/docs/rails_install_debian/)




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

Code:
$  cd myapp
$  rails server
Code:
http://localhost:3000
Want to make webrick faster?
[spoiler]
You can make webrick more responsive on remote machines by following this:
http://stackoverflow.com/questions/1...remote-desktop
I found my webrick config file at:
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/config.rb

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




TANGENT

Oh crap... At some point, I broke my nginx server. It now thinks its root is:
/var/www
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 192.168.0.4 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.

/TANGENT



ref: http://kevin.vanzonneveld.net/techbl..._ubuntu_lucid/
(you might need some of this still too. Some we installed previously, but w/e.)
Code:
$  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)
Code:
# this is a super cool hello world example
puts "hello world"
puts "!" * 5
puts 1 
puts "!" * 3

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

Comments

 

  



All times are GMT -5. The time now is 10:55 AM.

Main Menu

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