How to Install Django on Ubuntu 24.04?
Django is popular for developers looking to create robust web applications. Basically, it is a Python-based web framework that offers pragmatic design, and rapid as well as clean development. Installing Django on Ubuntu 24.04 sets up a robust environment for developing dynamic websites and applications. In addition, developers take advantage of its built-in features to handle common web development tasks.
This article will teach the step-by-step process to install as well as configure Django on the Ubuntu system based on supported content:
How to Install Django on Ubuntu 24.04?
On Ubuntu 24.04, Django helps developers take their applications from concept to completion as quickly as possible, and it emphasizes reusability, less code, low coupling, and rapid development. To install Django on Ubuntu 24.04, follow the below methods:
- Method 1: Using Ubuntu Official Repository
- Method 2: Using a Git Repository
- Method 3: Using a Virtual Environment
Method 1: Install Django on Ubuntu 24.04 Using the Ubuntu Official Repositories
To install Django on Ubuntu 24.04 from the official repositories, follow these steps:
Step 1: Update System Packages
First, ensure that your system packages are updated by opening the terminal and running the “update” command:
sudo apt update
Once the packages are updated, check if Python is installed since Django is a Python framework.
Step 2: Check Installed Python
Python typically comes pre-installed on Ubuntu, but users can verify the installed version by executing the “version” option in the terminal:
python3 --version
If Python is not installed, users are required to install it before installing Django:
sudo apt install python3-pip
Step 3: Install Django
Next, install Django using the “python3-django” package name with the “apt” command:
sudo apt install python3-django
Step 4: Check Django Version
After the installation is done, authenticate it by verifying the Django version with the “–version” option:
python3 -m django --version
It returns the installed version of Django, confirming that the installation is done successfully.
Method 2: Install Django on Ubuntu 24.04 Using a Git Repository
To install Django on Ubuntu 24.04 from the Git repository, users need to follow a series of steps setting up Python, pip, and virtual environments:
Step 1: Update Packages List
First, make sure that all your packages are up to date by running the below command:
sudo apt update
Step 2: Install Python, pip, and Python Environment
Then, install the necessary dependencies including Python, pip packages, and Python environment with the apt command:
sudo apt install python3 python3-pip python3-venv
Step 3: Clone the Django Repository from GitHub
Once dependencies are installed, users can now clone the Django Git repository. For instance, use the below URL to clone the repository into the home directory:
git clone https://github.com/django/django.git
Step 4: Create a Virtual Environment
Once cloned, move to the folder containing the Django repository. Then, create a new virtual environment “myenv” in the “django” directory with the “venv” option:
cd django python3 -m venv myenv
Step 5: Activate Virtual Environment
After creating a virtual environment, activate it by specifying the “myenv/bin/activate” path:
source myenv/bin/activate
Step 6: Install Django
To install Django from the repository, run the “-e” option with the “pip” command for editable mode, which is useful for development:
pip install -e ~/django
Step 7: Check the Django Version
After the installation, you can verify it by checking the Django version:
django-admin --version
It returns the version of Django that has been installed. With Django installed, let’s start developing your web applications on Ubuntu 24.04.
Method 3: Install Django on Ubuntu 24.04 Using a Virtual Environment
For a more isolated environment of Django, you need to consider the virtual environment. For installing Django on Ubuntu 24.04 using a virtual environment, follow the below steps:
Prerequisites: Check the Python Version
Before beginning, ensure that users have Python 3 installed, as Django is a Python framework. Users can verify the Python version by running the “python3” command with the “-V” or “version” option:
python3 -V
Step 1: Install Python and pip
If not installed, the first step is to install Python 3 and pip for setting up a virtual programming environment:
sudo apt update sudo apt install python3 python3-pip
Step 2: Set Up a Virtual Environment
It’s a good practice to utilize a virtual environment for the Django project. It basically isolates the project’s configurations from the pre-installed Python packages. To set up a virtual environment, first install the “venv” module:
sudo apt install python3-venv
Then, create the project directory and navigate to the folder where users need to save the Django projects such as “myproject”:
mkdir myproject cd myproject
Now, create a new virtual environment “myenv” within the project directory:
python3 -m venv myenv
Once the creation of the virtual environment is done, activate it using the “source” command. The command prompt reflects the activated environment:
source myenv/bin/activate
Step 3: Install Django
With the virtual environment active, install Django with the help of pip. It downloads as well as installs on Ubuntu 24.04:
pip install django
Step 4: Verify Django Installation
Finally, verify the installation by checking the Django version:
django-admin --version
Tip: If you have a firewall enabled, ensure that the port Django uses (default is 8000) is open. If not, execute the below command to enable:
sudo ufw allow 8000
That is all from the installation of Django on Ubuntu 24.04 using Git.
How to Setup/Start Django Project on Ubuntu 24.04?
Once, Django is installed on Ubuntu 24.04, users can set up/start the Django project on it via the below steps:
Step 1: Start a New Project
First, users start a new project with the “django-admin” command by specifying the project name. For instance, the project name is “mysite” (in the continuity of Method 3):
django-admin startproject mysite
Step 2: Run the Development Server
Then, navigate into your project folder named “mysite” and run the development server to ensure everything is working:
cd mysite python manage.py runserver
Step 3: Access Django Web Page
Now, users can see the Django welcome page by visiting “http://127.0.0.1:8000/” in the web browser:
Fix: Unapplied Migration(s) Error
If users find any unapplied migration(s) or project may not work properly error, run the “manage.py” file with the “migrate” option:
python manage.py migrate
Step 4: Create Django Admin Credentials
To access the admin interface, users need to create a superuser and its password. Let’s create “admin” as a superuser and its password:
python manage.py createsuperuesr
Step 5: Access the Django Admin Interface
Now, use the /admin/ after the end of your URL “http://127.0.0.1:8000/” to access the admin interface. Then, enter the credentials that are created as above:
After pressing the “LOG IN” button, navigate to the Admin Interface as below:
You’ve now successfully set up Django on your Ubuntu 24.04 system. From here, you can begin developing your web applications,
For more detailed instructions or additional configurations, such as setting up a database or deploying your Django application, refer to the official guide.
Bonus Tip: Uninstall/Remove Django on Ubuntu 24.04
To uninstall Django on Ubuntu 24.04 using the official repositories, remove the Django package by using the “python3-django” package name:
sudo apt remove python3-django sudo apt autoclean && sudo apt autoremove # Remove Unused Dependencies pip uninstall django # Remove Django via pip (After Navigating Installed Folder)
This will clean up the system by removing unnecessary files and packages related to Django.
Conclusion
To install Django on Ubuntu 24.04 using the virtual environment, update the package list, and install pip and venv. Then, create a directory for the Django project and navigate into it. Furthermore, create a virtual environment and activate it. Finally, install Django using the “pip install django” command.
Alternatively, use the Ubuntu default repository, and Git repository for installing Django on Ubuntu 24.04. The virtual environment method ensures that the Django installation is contained within a project-specific environment.
Use the Ubuntu default repository method for ease, while for development purposes, use the Git repository method.
























