How could we run multiple Rails Projects of different versions on a same server? 28Oct, 2014

RVM works with OS and Passenger to set the conditions of the current execution. For example, when you change the directories from one project directory to another with the cd command, rvm uses either the .rvmrc or the .rbenv file to see which ruby and which set of gems you want to use, and makes them the current set. In that manner, it sets only one version at a time, because you can be in one project at a time.

Every request handled by a web server can only use a single version of ruby to satisfy that request, just as the single user sitting at the keyboard can use a single version of ruby only. But since every request is independent of every other request, (that’s the nature of http) no request is required to use the same version of ruby as any other request. (Though it’s useful that all the requests coming to the same app, use the same ruby. It’s possible to set up some sort of randomization process that changes the ruby for each request randomly. Why anyone would want to do that is beyond my understanding, but it’s possible nonetheless.)

RVM works with Passenger through the PassengerRuby configurations for each virtual host in the configuration file. (Start with and go to for full apache information or for full nginx information.) These configurations are set independently for each virtual host, just as the document root, names and permissions are set independently for each virtual host. Then each request to that virtual host is handled by that version of ruby with the accompanying gemset.

Seriously, it’s all in the docs. It’s done every day in thousands of servers. Both of the passenger doc references I gave, walk through installing passenger in several systems. Google knows how many blog posts elaborate on it. If you’re not sure of what you’re doing, play around with a test system until you feel more comfortable with it. (The test system could be a spare machine or simply a regular system with an extra hard drive that you’ve set up to boot your OS configuration for testing. Since you don’t need much in terms of resources for that kind of testing, I’ve been known to use a largish thumb drive in one USB port as the test system’s boot drive with a second one in another USB port, as the backup/reset drive image. Using VirtualBox with some available VM’s is another quick and easy way to spin up a test system that you can throw away when you’re done.)

But if you don’t trust that solution, that’s fine, there are other approaches, such as the one mentioned earlier using one web server to proxy requests to other web servers, with each of them handle their own “universe” as it were. In the early days of rails we used apache as a main server proxying to a bunch of mongrel (Zed Shaw’s ruby-based web server) servers doing the actual rails work. Then Phusion came out with the Passenger, (essentially mod_rails for Apache) and it became simpler to do things without proxies. You could even bring in Tomcat and JRuby if you’d prefer to work in a JVM environment. I just think the rvm method is the simplest for you to set up, provided what you’ve said about the projects.

Install and configure passenger and nginx

– Once Ruby on Rails is installed, go ahead and install passenger by entering the line into the terminal: gem install passenger

As we want to install Rails on an nginx server, we only need to enter one more line into the terminal: rvm sudo passenger-install-nginx-module

Passenger first scrutinizes that all the dependencies it needs to work on are installed. If you are missing on any of these, then the Passenger will let you know how to install them either with the apt-get installer on Ubuntu.

Passenger offers users the choice between an automated setup or a customized one. Press 1 and enter to choose the recommended easy installation.

– The last step is to turn start nginx as it does not do so automatically. You can start it by following a command: sudo service nginx start

– Once you have installed rails, open up the nginx config file using terminal and type: sudo nano /etc/nginx/nginx.conf

– Make changes to the configuration file and your config should then look something like this:

server {
listen 80;
passenger_enabled on;
root /var/www/my_awesome_rails_app/public;

Posted by: DineshSaini / In: Ruby on Rails and Tagged ,

Leave a Reply

Your email address will not be published.