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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more