Skip to content

How to fix Error: That port is already in use?

  • by
  • 2 min read

There are several different web development frameworks for developers to choose from, ranging from React or NextJS, which rely heavily on JavaScript and Django, which uses Python. That said, as simple as they’ve made web development, some bugs and issues still stump developers. 

In this article, we’re talking about the “Error: That port is already in use” issue when launching a webserver with Django, its causes and what you can do to fix the issue. 


What causes this error?

As you can probably guess from the error message itself, the issue is caused by Django running multiple webservers on the same port. Each webserver requires its own unique port to run on, and Django’s default port number is 8000.

If you try and run multiple projects without first specifying a port number, Django will try to run all of them on port 8000, which can cause this error. 

Also read: Fix: Authenticate/decrypt packet error: packet hmac authentication failed


How to fix this?

The error can be fixed by launching the webserver on a different port. To do so, you’d use the following command:

python manage.py runserver 0.0.0.0:x

Where ‘x’ is the four-digit port number you want to use for the server. Note that it can be any number other than 8000, as then you’d run into the same error again. 

Top 7 games for kids to learn coding | Candid.Technology

It’s also recommended that you close any processes using the 8000 port before launching your Django project. If you’re on Linux, use this command:

sudo fuser -k 8000/tcp

macOS users can use the following command.

sudo lsof -t -i tcp:8000 | xargs kill -9

Remember that if no process uses the 8000 port, your Django server will run fine without you specifying a port number. This means you can run the aforementioned commands to kill any processes associated with the 8000 port and run your webserver as usual without any problems whatsoever. 

However, if you want to run multiple web servers simultaneously, it becomes important to mention the port number in the run command. 

Also read: How to fix HTTP error 500.30 – asp.net core app failed to start?

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: yadullahabidi@pm.me.

>