Flask development server default port: 5000

Flask development server uses TCP port 5000 by default. Flask does not pick another port. If port 5000 is taken, flask run prints “Address already in use”, says the port is in use by another program, and exits with status 1.

Updated

Key facts

Default ports for Flask development server
PortProtocolRoleCategory
5000TCPflask run development serverBackend

What happens when the port is busy

Flask does not pick another port. If port 5000 is taken, flask run prints “Address already in use”, says the port is in use by another program, and exits with status 1. The Flask documentation describes the same failure as an OSError (Errno 98, or WinError 10013 on Windows). Stop the other program or run flask run --port 5001. On macOS Monterey and later a system service already uses port 5000, so a fresh Flask project can hit this on its first run.

Change the port

CLI flag
flask run --port 5001

With an app name, put the app option before run: flask --app hello run --port 5001.

Environment variable
export FLASK_RUN_PORT=5001
flask run

Flask names command options FLASK_COMMAND_OPTION, so the port for flask run is FLASK_RUN_PORT.

.flaskenv file
FLASK_RUN_PORT=5001

The flask command loads .env and .flaskenv only when python-dotenv is installed. Variables set on the command line are used over .env, which is used over .flaskenv. Commit .flaskenv for shared settings and keep .env out of Git.

Turn off AirPlay Receiver on macOS
System Settings > General > AirDrop & Handoff > AirPlay Receiver (switch off)

That is the path on macOS 13 and 14, and the pane name can differ in other versions. On macOS 12 Monterey the switch is under System Preferences > Sharing > AirPlay Receiver. In any version, search System Settings for AirPlay Receiver, as the Flask documentation says.

Environment variable: FLASK_RUN_PORT. Sets the --port option of flask run. A bare PORT variable is not part of Flask’s FLASK_COMMAND_OPTION naming, so a process runner that exports only PORT does not move flask run by itself.

Bind address

Binds to 127.0.0.1 by default, so only your own machine can reach it. The Flask documentation gives the reason: with the debugger on, a user of the application can execute arbitrary Python code on your computer. --host=0.0.0.0 makes the server available to the network, which the documentation says is acceptable if the debugger is off or you trust the users on your network.

What else uses this port

No other tool in this dataset uses port 5000 as a default.

The dataset is the 12 tools on the ports index.

Find and free this port

These commands find the process that holds TCP port 5000 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:5000 -sTCP:LISTEN
ps -p PID_NUMBER -o pid,ppid,user,command
kill -TERM PID_NUMBER
Linux (bash)
ss -ltnp 'sport = :5000'
ps -p PID_NUMBER -o pid,ppid,user,command
kill -TERM PID_NUMBER
Windows (PowerShell)
Get-NetTCPConnection -LocalPort 5000 -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 5000, the next three ports that no tool in this dataset uses as a default are 5001, 5002, and 5003. 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: flask run becomes a selectable script run through /bin/sh -c. When a port is set, Rig appends --port N to the command and exports PORT, VITE_PORT, HOST_PORT, and npm_config_port. Flask documents --port as a flask run option, so the appended flag does what it says, and FLASK_RUN_PORT is not among the exported variables. When 5000 is held, who_owns_port returns the owner and the first free port in the 50 above it, and start_project can kill the owner, switch ports, or return a portConflict.

Collisions in practice

Flask’s default of 5000 is a port that macOS itself can occupy. Since macOS Monterey a built-in service holds port 5000, and Apple lists 7000 for AirPlay as well, so a new Flask project can fail on its first flask run on a Mac while the same code starts without trouble on a Linux server. Moving to 5001 fixes today’s run but not your teammate’s machine. Put FLASK_RUN_PORT in .flaskenv, with python-dotenv installed, so every checkout agrees on the port.

Frequently asked questions

Why is port 5000 already in use on my Mac when I have nothing running?

Since macOS Monterey a system service uses port 5000. It is the AirPlay Receiver, and Apple lists 5000 and 7000 TCP as AirPlay ports. Turn it off in System Settings, General, AirDrop & Handoff on macOS 13 and 14 (the pane name can differ in other versions, so search System Settings for AirPlay Receiver), or leave it on and run flask run --port 5001. On macOS 12 the switch is in System Preferences, Sharing. Current Werkzeug, the server Flask uses, prints a hint to disable AirPlay Receiver when port 5000 is busy on a Mac.

Can I open flask run from my phone?

Pass --host=0.0.0.0, for example flask run --host=0.0.0.0. The Flask documentation says to do this only when the debugger is off or you trust the users on your network, because the debugger lets a user of the application run arbitrary Python on your computer.

Should I use FLASK_RUN_PORT or --port?

They set the same option. Use --port for a one-off run and FLASK_RUN_PORT in .flaskenv when everyone on the project should get the same port. python-dotenv must be installed for .flaskenv to load, and variables set on the command line are used over .env, which is used over .flaskenv.

Sources

  1. Flask documentation: quickstart (127.0.0.1:5000, --host=0.0.0.0, debugger warning)Official documentation, checked 13 October 2026
  2. Flask documentation: development server (address already in use, macOS Monterey and AirPlay Receiver, --port 5001)Official documentation, checked 13 October 2026
  3. Flask documentation: command line interface (FLASK_RUN_PORT, .env and .flaskenv, python-dotenv)Official documentation, checked 13 October 2026
  4. Apple Support: change AirDrop and Continuity settings on Mac (AirPlay Receiver)Official documentation, checked 13 October 2026
  5. Apple Support: change AirPlay Receiver preferences on Mac (macOS 12 Monterey)Official documentation, checked 13 October 2026
  6. Apple Support: TCP and UDP ports used by Apple software products (5000 and 7000 TCP, AirPlay)Official 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/flask