How to change Rails default development server port

October 22nd, 2008  | Tags:

If you work on multiple rails apps at once (eg. an app and a webservice), it is sometimes necessary to run rails development apps on a different ports. You can of course do this when you start the rails app by adding the -p switch.

But here is a way to set the default development port per app. Update script/server to look like this:

#!/usr/bin/env ruby
default_port = 3001

if RAILS_ENV='development'
  ARGV << "-p#{default_port}" unless ARGV.to_s.include?("-p")
end

require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
  1. September 3rd, 2009 at 10:50
    Reply | Quote | #1

    Great thanks! Just a fix:

    if RAILS_ENV=’development’

    should be

    if ENV['RAILS_ENV'] == ‘development’

    :-)

  2. January 12th, 2010 at 16:10
    Reply | Quote | #2

    This doesn’t seem to work for me running rails 2.3.5. Has this worked for you on that version? Any thoughts on why it might not work or another way to do it?

TOP