Rails 7 set puma port

I’m starting my development server with bin/dev which in turn starts Puma listening on port 5000 Why the change from previously common port 3000 and can I change it back to 3000 and how?

Look in your lib/Procfile.dev and see what it is set to. Did you change that ever?

It’s set to “bin/rails server” config/puma.rb has it set with "port ENV.fetch(“PORT”) { 3000 } " I’m wondering where the environment gets set

You can replace the content of the procfile with the following line; it will unset existing ports and point to the default one (3000)

web: unset PORT && bin/rails server

Alternatively, you can also set your own port this way with -p:

web: unset PORT && bin/rails server -p 3000

Hey, I’ve kicked off my development server using the trusty ol’ bin/dev command, which fires up Puma and sets it to listen on port 5000. Now, here’s the thing – I’m used to the good old default port 3000, and I’m wondering why the change? Was there a specific reason for switching it up? Also, I’m curious if there’s a way to revert back to port 3000 if that’s what I’m more comfortable with. If anyone has insights on the port change and can guide me through switching it back or perhaps offer some pros and cons, I’d be absolutely thrilled to hear your thoughts.

Welcome! I don’t recall ever seeing this behavior before, so it would be worthwhile reviewing the contents of your Procfile.dev file to see if it actually sets a different port. Another couple of questions: you are speaking here about running in a local terminal, not in a container on your machine, or on a server somewhere, right? And you are completely sure that you are in the development environment, right? If you put this ERB in a template somewhere visible, and navigate to it in a browser, what do you see on the screen?

<%= Rails.env %>


Foreman automatically provides a PORT environment variable to every launched process which increments by one each time. It starts at 5000. So if your Procfile’s first line entry is starting the Rails server, it will get the PORT environment var set to 5000.

If you want to change this, and you probably should since MacOS now takes port 5000 for it’s own use, you can start foreman like this: foreman start -p <PORT_NUMBER> or put PORT=3000 in the .env file.

1 Like