7

I want to set the default port when I do

rails s

to 3010, instead of having to say:

rails s -p 3010

...every time. Any ideas?

Allyl Isocyanate
  • 13,306
  • 17
  • 79
  • 130

1 Answers1

11

You can override the Port by adding the following code to config/boot.rb

require 'rails/commands/server'
module Rails
  class Server
    alias :default_options_alias :default_options
    def default_options
      default_options_alias.merge!(:Port => 3010)
    end    
  end
end
asitmoharna
  • 1,484
  • 11
  • 15
  • This doesn't seem to work for me (using Eclipse/Aptana). The port is still 3000 after starting the server. – Josh M. Sep 20 '13 at 12:06
  • 7
    FWIW, Rails 4.2 and higher now default to binding only to localhost instead of all interfaces. You can use `default_options_alias.merge!(:Host => '0.0.0.0')` in the above example to restore the former functionality if you need to access WEBrick from an outside machine. – Tobias J Dec 10 '14 at 18:54
  • More info on this at https://stackoverflow.com/questions/3842818/how-to-change-rails-3-server-default-port-in-develoment , especially the use of `super.merge({Port: 3010})` instead of the alias merge line. Both versions are working for me under Rails 4.2.11.3, Ruby 2.2.3. – Tom Hundt Jan 12 '21 at 05:59