DEV Community

Subash
Subash

Posted on

3

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.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

Image of Stellar post

🚀 Stellar Dev Diaries Series: Episode 1 is LIVE!

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

If this post resonated with you, feel free to hit ❤️ or leave a quick comment to share your thoughts!

Okay