views:

340

answers:

4

Hello,

I have Ruby 1.8.7 and 1.9 install. I run the different ones by specifying ruby or ruby1.9 when running commands. for example

ruby --version

or

ruby1.9 --version

however when I want to create new rails application the command available is rails such as:

rails my_app_name

How do I specify when I call the 'rails' command to create new rails app or does it matter? I mean if I create it with one version it will be the same code of the other version or does the generator script user different code for different Ruby versions.

Thanks,

Tam

A: 

Doesn't matter, the rails structure is quite the same.

Lichtamberg
+2  A: 

The simplest way is to use the -S option. For example and according to your case, to use Ruby 1.9 you can do:

# Create new Rails project with Ruby 1.9
ruby1.9 -S rails new_app

# Run the project with Ruby 1.9
ruby1.9 script/server

#install new gems for Ruby 1.9
ruby1.9 -S gem install some_gem

# Use Rake with Ruby 1.9
ruby1.9 -S rake something

And as your default Ruby interpreter is the 1.8.7 one, then just keep the normal use of it, no need for -S option.

khelll
Thanks Khell. I tried it ut I'm getting this error:ruby1.9 -S rails wiss<internal:gem_prelude>:249:in `push_gem_version_on_load_path': undefined method `<=>' for nil:NilClass (NoMethodError) from <internal:gem_prelude>:14:in `gem' from /usr/bin/rails:18:in `<main>'
Tam
Have you installed Rails for Ruby 1.9? Are you using packaged Rails in vendors folder? What version of Rails are you Running?
khelll
I'm using ruby 1.9. If I type: ruby1.9 --version I get ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9]
Tam
You didn't answer any of my questions....
khelll
Sorry for that. Yes I did...I have ruby 1.9 installed as ruby1.9 and the gem command is gem1.9. So I used gem1.9 install rails and it installed correctly and if I type gem1.9 list I see rails (2.3.4)there.
Tam
There must have been something wrong with my installation. Re-installing did the trick..
Tam
+1  A: 

I use passenger/mod_rails for development locally (on Mac OSX Snow Leopard). In the apache (or nginx) conf file where passenger's settings live, you set a "PassengerRuby" environment variable. You can point this to whichever ruby installation you're wanting to use (don't forget to restart apache afterwards).

I'm using RVM at the moment for managing my ruby installations. In my user's apache conf file I've got the default Mac OSX snow leopard 1.8.7 set up with passenger, and then also one for a 1.8.6 installation via RVM. Whichever one I want to use is left un-commented. Here's how it looks at the moment:

# Default passenger
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.5
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

# Use RVM 1.8.6 ruby
# LoadModule passenger_module /Users/dylanfm/.rvm/gems/ruby/1.8.6/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
# PassengerRoot /Users/dylanfm/.rvm/gems/ruby/1.8.6/gems/passenger-2.2.5
# PassengerRuby /Users/dylanfm/.rvm/bin/ruby-1.8.6-p383
dylanfm
A: 

For unix type OSes. You could also link executables for ruby1.8/1.9 to ruby, gem1.8/1.9 to gem and etc. Something like:

ln -sf /usr/bin/ruby1.8 /usr/bin/ruby
ln -sf /usr/bin/gem1.8 /usr/bin/gem
...

You can find paths to your ruby/gem/rake/etc. executables by using which command. You could alias these commands as use18, use19 for example.

Andrius