0

I have a development machine running ruby 1.9.3p545 and rails version Rails 3.2.13 and currently has 5 applications with their capistrano scripts.

I now want to develop a new application using the same machine but with Ruby 2.0.0 and Rails 4.1.

How can i do this without conflict. Thanx!

acacia
  • 1,375
  • 1
  • 14
  • 40

2 Answers2

1

Rbenv: https://github.com/sstephenson/rbenv

Ruby-build: https://github.com/sstephenson/ruby-build

Rbenv Installation

As root

cd /opt
git clone git://github.com/sstephenson/rbenv.git rbenv

touch /etc/profile.d/rbenv
echo 'export RBENV_ROOT=/opt/rbenv' >> /etc/profile.d/rbenv
echo 'export PATH=/opt/rbenv/bin:$PATH' >> /etc/profile.d/rbenv
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv

edit /root/.bashrc and add on the very top of the file

source /etc/profile.d/rbenv

edit /home/#your_user_name#/.bashrc and add on the very top of the file

source /etc/profile.d/rbenv

Ruby-build installation

exec $SHELL
mkdir -p $RBENV_ROOT/plugins
cd $RBENV_ROOT/plugins
git clone git://github.com/sstephenson/ruby-build.git
echo 'export PATH="$RBENV_ROOT/plugins/ruby-build/bin:$PATH"' >> /etc/profile.d/rbenv
exec $SHELL

At that point you are all set-up, ready to install any version of ruby

Ruby Installation

Example with versions 2.1.2 and 1.9.3p545, but you can choose any version you want

rbenv install 2.1.2
rbenv install 1.9.3p545

Set global version of ruby

rbenv global 2.1.2

Set locale version of ruby

cd /your/project/directory
rbenv local 1.9.3p545

Install Bundler

Note that before running bundler from your application root to install your gems you will have to install bundler it self with the following command

gem install --no-rdoc --no-ri bundler rake
rbenv rehash

Update rbenv

cd /opt/rbenv
git pull
cd /opt/rbenv/plugins/ruby-build
git pull
rbenv rehash
Benjamin Bouchet
  • 12,971
  • 2
  • 41
  • 73
1

You may checkout this awesome article: Phusion Passenger & running multiple Ruby versions

Basically, you could use rvm and reverse proxy to get it done. In your case, ruby -v 2.0.0, if you use passenger you could:

  • rvm use 2.0.0
  • gem install passenger --pre
  • cd /path/to/your/app
  • passenger start -a 127.0.0.1 -p 3000 -d
  • setup reverse proxy in your apache config

    <VirtualHost *:80>
      ServerName www.hamburgers.com
      DocumentRoot /path/to/your/app/public
      PassengerEnabled off
      ProxyPass / http://127.0.0.1:3000
      ProxyPassReverse / http://127.0.0.1:3000
    </VirtualHost>
    

you could also try use unicorn instead of passenger, or replace apache with ngix.

KilenZhang
  • 21
  • 3