Welcome to our guide on how to Install Pip3 and Django on Ubuntu 22.04|20.04|18.04 LTS. Django is a free and open source high-level Python Web framework designed to encourage rapid Web development without the need to reinvent the wheel. Pip is a package management system used to install and manage software packages written in Python.
This guide will take you through the steps to install Pip3 & Django on Ubuntu 22.04|20.04|18.04 LTS systems. This works for both Desktop and server installations.
Step 1: Install Python3 and Pip3
Your Ubuntu system should come with Python 3, if it doesn’t have it, install by running the commands below on your terminal.
sudo apt update
sudo apt -y install python3 python3-pip
Step 2: Install Django on Ubuntu22.04|20.04|18.04
The easiest and quickest way to Install Django on Ubuntu22.04|20.04|18.04 LTS is via pip3.
Check your Python version:
### Ubuntu 22.04 ###
$ python3 -V
Python 3.9.9
### Ubuntu 20.04 ###
$ python3 -V
Python 3.8.10
Check installed pip3 version:
### Ubuntu 22.04 ###
$ pip3 -V
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)
### Ubuntu 20.04 ###
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
Upgrade Pip3 to the latest upstream release:
$ sudo -H pip3 install --upgrade pip
Collecting pip
Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
|████████████████████████████████| 1.7 MB 10.5 MB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.0.2
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'pip'. No files were found to uninstall.
Successfully installed pip-21.3.1
Confirm the latest updated version of pip3
$ pip3 --version
pip 21.3.1 from /usr/local/lib/python3.9/dist-packages/pip (python 3.9)
Add ~/.local/bin/
in your PATH, add it like below:
echo 'export PATH=$PATH:~/.local/bin/' | tee -a ~/.bashrc
Source the bashrc file
source ~/.bashrc
Download and install Django on Ubuntu22.04|20.04|18.04:
$ pip3 install --user Django
Collecting Django
Downloading Django-3.2.9-py3-none-any.whl (7.9 MB)
|████████████████████████████████| 7.9 MB 10.3 MB/s
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
|████████████████████████████████| 42 kB 3.8 MB/s
Requirement already satisfied: pytz in /usr/lib/python3/dist-packages (from Django) (2021.3)
Collecting asgiref<4,>=3.3.2
Downloading asgiref-3.4.1-py3-none-any.whl (25 kB)
Installing collected packages: sqlparse, asgiref, Django
Successfully installed Django-3.2.9 asgiref-3.4.1 sqlparse-0.4.2
For global installation, use:
sudo pip3 install Django
The installation of Django will give you django-admin
command to manage Projects,
$ command -v django-admin
/home/jmutai/.local/bin/django-admin
Check django-admin
version using:
$ django-admin --version
3.2.9
Step 3: Create a test Django Application
Create a Django test application by running
mkdir projects
cd projects
django-admin startproject test_app
cd test_app
test_app
is the name of our Django Project.
Apply pending migrations
$ python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying sessions.0001_initial... OK
Step 4: Create an Admin Account
Create a Django project superuser account by running the following commands from your Django application directory.
$ python3 manage.py createsuperuser
Username (leave blank to use 'jmutai'): admin
Email address: [email protected]
Password: <INPUT-PASSWORD>
Password (again): <CONFIRM-PASSWORD>
Superuser created successfully.
Input your admin username, email address, and password.
Step 5: Allow external access to the Django web application (Optional)
Note that by default Django doesn’t allow external access to the application, you need to explicitly define an ACL.
vim test_app/settings.py
Edit the lineALLOWED_HOSTS
to whitelist your Computer IP or LAN subnet.
ALLOWED_HOSTS = ['192.168.18.50']
A value of ‘*‘ will match anything:
ALLOWED_HOSTS = ['*']
You can now start Django application server:
$ python3 manage.py runserver 0.0.0.0:8080
Performing system checks...
System check identified no issues (0 silenced).
November 10, 2018 - 12:08:27
Django version 2.1.3, using settings 'test_app.settings'
Starting development server at http://0.0.0.0:8080/
Quit the server with CONTROL-C.
If you open the URL http://[server IP/hostname]:8080
you should see a successful message like below:
Django Administration page is available on :8080/admin
Login with created username and password:
The admin page allows you to add other users, add groups, change password e.t.c. It looks like below:
You now have Django Framework installed on your Ubuntu 22.04|20.04|18.04 LTS system.