Ruby on Rails

How to run multiple rails server instances on your local machine

Most of the times, you are developing more than one rails project at the same time and you want to avoid switching directories and start/stopping your development server. Running multiple rails server instances on your local machine is a daily essential. This minipost will demonstrate how to run multiple server instances using the -p option.

In order to start a single development rails server instance, you have to navigate to the project directory via the command line and execute the following command:

rails s

After that, the server starts at the default port 3000 by displaying the following information (depending on your setup):

=> Booting Thin
=> Rails 4.2.7.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:3000, CTRL+C to stop

You can now navigate to http://localhost:3000/ and interact with the application.

Starting multiple rails s instances on different ports

As we have seen already by default rails s runs the application on the 3000 port. In order to run a development server on a different port you have to use the -p option by supplying the desired port:

rails s -p 3001

Now, to interact with the newly server instance you have to navigate to http://localhost:3001/. It is quite obvious that you can use as many ports as you like and have multiple server instances running concurrently on the specified ports. This option works with all the development web servers (WEBrick, Thin, etc.)