> ## Content Index
> Fetch the complete content index at: https://www.javahandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to fix the "port 8080 already in use error on Windows and macOS
- URL: https://www.javahandbook.com/blog/how-to-fix-the-port-8080-already-in-use-error-on-windows-and-macos/
- Published: 2025-08-16T02:51:49.000Z
- Updated: 2025-08-17T02:27:54.000Z
- Author: Gopi Gorantala
- Tags: #blog, #template-toc, spring-boot-common-errors, spring-errors

If you're trying to start a web server and see the error:

> **“Web server failed to start. Port 8080 was already in use.”**

You're not alone. This is a common problem when a port of your app needs—often `8080` for development—is already being used by another process. Here's what’s happening and how to fix it on Windows and macOS.

## 🔍 What Does This Error Mean?

Ports are like doors that apps use to communicate over the network. If another program is already using port 8080, your server will crash with that error.

**Common culprits:**

- Another instance of your app is already running
- A browser-sync tool or frontend server
- Docker, Jenkins, Tomcat, or other dev tools

## 🛠 How to Fix It on **Windows**

### Step 1: Find the Process Using Port 8080

Open **Command Prompt** and run:

```bash
netstat -ano | findstr :8080
```

This shows you the PID (Process ID) using port 8080.

Example output:

```bash
  TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       12345

```

Here, `12345` is the PID.

### Step 2: Kill the Process

Now run:

```bash
taskkill /PID 12345 /F

```

Replace `12345` with the PID from the previous command. The `/F` flag forces the process to terminate.

---

## 🛠 How to Fix It on **macOS**

### Step 1: Find the Process Using Port 8080

Open **Terminal** and run:

```bash
lsof -i :8080

```

This lists processes using port 8080.

Example:

```bash
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node     6789 john   22u  IPv6 0x...      0t0  TCP *:http-alt (LISTEN)

```

Here, `6789` is the PID.

### Step 2: Kill the Process

Run:

```bash
kill -9 6789

```

The `-9` flag forcefully stops the process.

---

## Alternative Solutions and Best Practices

1. **Change your server’s port**
  - **Spring Boot**: set `server.port` in `application.properties`/`application.yml`, or pass `--server.port=9090` on the command line.
  - **Node.js**: modify the port constant in your startup script, e.g. `app.listen(process.env.PORT || 3000)`.
2. **Graceful shutdown hooks**  
Implement shutdown hooks in your application so it unbinds cleanly—especially important for Java apps (e.g. using a `@PreDestroy` method or `Runtime.getRuntime().addShutdownHook(...)`).
3. **Port-checking scripts**  
Add a lightweight preflight check in your build or startup scripts to detect free ports and either notify you or automatically pick an available port.
4. **Docker port mappings**  
If you’re running in containers, ensure your `docker run -p` or `docker-compose.yml` mappings don’t collide with the host ports you need.
5. **Continuous monitoring**  
Use basic monitoring tools (e.g., `fd://` or simple cron jobs) to alert you when port conflicts arise in staging or production.

## ✅ After That...

Try restarting your server. If it starts successfully, you’re good.

To avoid the issue in the future:

- Make sure to shut down local servers when you’re done
- Consider changing the port (e.g., to 3000, 5000) if 8080 is often in use