Skip to content

How to fix port 8080 already in use error on Windows and macOS

Getting the “Web server failed to start. Port 8080 was already in use” error? Learn how to identify and kill the process blocking port 8080 on Windows and macOS using simple terminal commands. Fix server startup issues fast and keep your development running smoothly.

Gopi Gorantala
Gopi Gorantala
2 min read
How to fix port 8080 already in use error on Windows and macOS
How to fix port 8080 already in use error on Windows and macOS

Table of Contents

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 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 already takes port 8080, your server can’t use it and crashes 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:

netstat -ano | findstr :8080

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

Example output:

  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:

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:

lsof -i :8080

This lists processes using port 8080.

Example:

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:

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
spring-boot-common-errorsSpringSpring Issuesjava frameworkshow-to

Gopi Gorantala Twitter

Gopi is an Engineering Manager with over 14 years of extensive expertise in Java-based applications. He resides in Europe and specializes in designing and scaling high-performance applications.

Comments


Related Posts

Members Public

Spring Boot Hello World Tutorial with Lombok and H2 Database – Quick Start for Beginners

Learn how to create a Hello World Spring Boot application using Lombok for cleaner code and the H2 in-memory database for rapid development. This step-by-step guide includes annotations, project setup, REST API, H2 console access, and more to kickstart your Spring Boot journey.

Spring Boot Hello World Tutorial with Lombok and H2 Database – Quick Start for Beginners
Members Public

Spring vs. Spring Boot: Key Differences Developers Must Know

Spring or Spring Boot? One gives you full control, the other gets you up and running fast. If you're building Java apps, knowing the difference isn't optional—it’s critical. Here’s the breakdown every dev should read.

Spring vs. Spring Boot: Key Differences Developers Must Know
Members Public

NoSuchBeanDefinitionException: The Most Common Spring Bean Error

Learn how to fix NoSuchBeanDefinitionException in Spring Boot with clear examples and best practices for dependency injection, package scanning, and bean registration.

NoSuchBeanDefinitionException for a missing bean in the ApplicationContext.