Rails server default port: 3000

Rails server uses TCP port 3000 by default. Rails does not look for another port. rails server resolves the port once, from -p, then the PORT environment variable, then 3000, so when that port is taken the web server cannot bind and the start fails.

Updated

Key facts

Default ports for Rails server
PortProtocolRoleCategory
3000TCPrails server development serverBackend

What happens when the port is busy

Rails does not look for another port. rails server resolves the port once, from -p, then the PORT environment variable, then 3000, so when that port is taken the web server cannot bind and the start fails. Choose a free port with -p or PORT and start again.

Change the port

CLI flag
bin/rails server -p 3001

-p takes priority over the PORT environment variable.

Environment variable
PORT=3001 bin/rails server

Used when -p is absent. Process runners such as Foreman set PORT for you, which is why an app can start on 5000 or another port you did not choose.

config/puma.rb
port ENV.fetch("PORT", 3001)

Current Rails (8.1) generates this line with 3000 as the fallback; older versions wrote port ENV.fetch("PORT") { 3000 }. If you also pass -p, check which value your Rails and Puma versions use before you rely on either.

Environment variable: PORT. rails server reads PORT when -p is not given, and the generated config/puma.rb reads it too. The port is 3000 when PORT is unset. The BINDING variable does the same job for the bind address.

Bind address

In development, rails server binds to localhost, and in other environments to 0.0.0.0. The -b (--binding) option or the BINDING environment variable overrides that default, for example bin/rails server -b 0.0.0.0 to reach the server from another device.

What else uses this port

TCP port 3000 is also the default for Next.js dev server and Nuxt dev server.

The dataset is the 12 tools on the ports index.

Find and free this port

These commands find the process that holds TCP port 3000 and stop it. They come from the Port in use command generator. PID_NUMBER stands for the process ID you read from the first command: replace it before you run the others.

macOS (zsh)
lsof -nP -iTCP:3000 -sTCP:LISTEN
ps -p PID_NUMBER -o pid,ppid,user,command
kill -TERM PID_NUMBER
Linux (bash)
ss -ltnp 'sport = :3000'
ps -p PID_NUMBER -o pid,ppid,user,command
kill -TERM PID_NUMBER
Windows (PowerShell)
Get-NetTCPConnection -LocalPort 3000 -State Listen -ErrorAction SilentlyContinue | Select-Object LocalAddress, LocalPort, State, OwningProcess
Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = PID_NUMBER" | Select-Object ProcessId, ParentProcessId, Name, CommandLine
Stop-Process -Id PID_NUMBER

Read the output of the second command before you stop anything, because the owner may be a container or another person’s process. Then run the first command again to confirm the port is free.

Next free ports

Counting up from 3000, the next three ports that no tool in this dataset uses as a default are 3001, 3002, and 3003. They are suggestions only: another program on your machine may hold any of them, so run the find command above before you choose one.

In Rig

Rig reads a file named exactly Procfile in the project root, so a line such as web: bin/rails server becomes a selectable script that Rig runs through /bin/sh -c. When a port is set, Rig exports PORT (along with VITE_PORT, HOST_PORT, and npm_config_port), which rails server reads, and appends --port N, the long form of -p. When 3000 is already held, who_owns_port returns the owner’s PID, command, and working directory plus the first free port in the 50 above it, and start_project can kill the owner, switch to a free port, or return a portConflict.

Collisions in practice

The Rails collision that surprises people is on 5000, not 3000. rails server reads PORT before it falls back to 3000, and Foreman sets PORT for every process it starts, with 5000 for the first one in its man page example. An app launched that way lands on the port macOS gives to AirPlay Receiver and Flask uses by default. When a Rails app answers on a port you did not choose, run env | grep PORT before you touch the code, and pin the port with -p in the Procfile line.

Frequently asked questions

Why does my Rails server start on port 5000 instead of 3000?

Something set PORT in the environment. rails server reads -p first, then PORT, and only then falls back to 3000. Foreman sets PORT for each process it starts, and its man page example shows 5000 for the first process and 5100 for the second. Run env | grep PORT, unset it or pass -p 3000, and the default returns.

Is rails server reachable from other devices by default?

Not in development. The Rails guide says -b binds to localhost by default, and the source uses localhost for the development environment. In other environments the default is 0.0.0.0. Run bin/rails server -b 0.0.0.0 when a phone or another computer needs to connect in development.

Where does config/puma.rb get its port?

The generated file reads PORT and falls back to 3000. Current Rails (8.1) writes it as port ENV.fetch("PORT", 3000), and the Rails 7 file quoted in a thread on the Rails forum has port ENV.fetch("PORT") { 3000 }. Both mean use PORT if it is set and 3000 otherwise. Because rails server also reads PORT, setting the variable moves both.

Sources

  1. Ruby on Rails Guides: the Rails command line (port 3000, -p, -b defaults to localhost)Official documentation, checked 13 October 2026
  2. rails/rails source (main): ServerCommand resolves the port from -p, then PORT, then 3000, and the host from -b or BINDINGOfficial documentation, checked 13 October 2026
  3. Rails forum: Rails 7 set puma port (generated config/puma.rb line and where PORT comes from)Official documentation, checked 13 October 2026
  4. Foreman manual: PORT is assigned per process from a base port, example output starts at 5000Official documentation, checked 13 October 2026
  5. Apple Support: TCP and UDP ports used by Apple software products (5000 and 7000 TCP, AirPlay)Official documentation, checked 13 October 2026
  6. Flask documentation: development server, port 5000 on macOS Monterey and laterOfficial documentation, checked 13 October 2026

Busy ports in Rig

When a start fails because a port is taken, Rig shows which process owns it when it can, and lets you reclaim the port or choose another. You do not need Rig to use this page.

Related

https://userig.app/ports/rails