DEV Community

Subash
Subash

Posted on

Rails default port

There might be cases where you need to utilize more than one port for an application in your local. For example web-server might be utilizing port 3000 and if you start rails engine by using the command rails server or rails s you will get an error Address already in use - bind(2) for "127.0.0.1" port 3000. So manually you need to specify rails to use a different port like rails s -p 3001

Actually there is a way you can specify the rails engine to use a specific port to use by default.

Just locate the rb file with the engine name under /config directory. In my case puma is the engine so lets open config/puma.rb.

The below line is responsible for using the port 3000 by default.

port ENV.fetch("PORT") { 3000 }
Enter fullscreen mode Exit fullscreen mode

Replace the 3000 with port whichever you want to use. In my case it is 3001

port ENV.fetch("PORT") { 3001 }
Enter fullscreen mode Exit fullscreen mode

That's it. Now start the server by default port 3001 will be used by rails.

Top comments (0)