Install django in Ubuntu
Learn various methods of installing the popular Python framework Django in Ubuntu.
Django is one of the most popular frameworks today based on Python.
But there are multiple ways to install Django and each is meant for a different purpose. And in this tutorial, I will share the following ways to install Django:
- Install with pipx (officially recommended way)
- Install development branch of Django (gets the most recent version)
- Install with apt, Ubuntu's package manager (easiest)
So let's start with the first and recommended way.
Install Django using Apt in Ubuntu (easiest)
By far this is the easiest way you can install Django in Ubuntu as you'll be using apt package manager so all you do is execute one command for the installation.
To install Django in Ubuntu, you can use the following command:
sudo apt install python3-django
If you want to verify the installation, you can check the installed version using the following command:
django-admin --version
Install Django in Ubuntu (recommended)
If you visit Django's official page, then, you'd know that they recommend using Django using pip as it provides flexibility and stability.
After Pip's new feature, you will get an externally-managed environment error if you went with the straight installation.
So installing packages virtually is the only option you have.
But installing packages in the virtual environment is a lengthy task and there comes the usage of the pipx that will install packages in a virtual environment.
First, you install the pipx in Ubuntu:
sudo apt install pipx
Once you are done with the installation part, add it to the $PATH variable so you can access installed packages from anywhere in the system:
pipx ensurepath
Now, log out and log back in to use the pipx.
To install Django, you can use the following command:
pipx install django
And as you can see, it gave me Django version 4.2.4.
But what if you want to have a development branch to get the most recent packages?
Install the Development version of Django (not recommended)
Here too, I will be using the pipx. But this time, you'd have to use Git.
So first, install Git in Ubuntu using the following command:
sudo apt install git
Now, clone the Django git repository:
git clone https://github.com/django/django.git
And finally, use the pipx to install the development branch of Django:
pipx install django/
As you can see, it gave me the latest version of Django 5.0 which is far ahead of anything I achieved with other methods.
Here's how to get the most out of pipx
If you're new to pipx and have no idea of how you install, search, upgrade, or remove packages installed through pipx, then, you can refer to our detailed guide on how to install and use pipx in Ubuntu:
I hope you will find this guide helpful.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.