How to Create a Django Project in Linux/Ubuntu 22.04.4
Table of Contents
Why Django on Ubuntu 22.04?
Ubuntu 22.04 LTS is a rock-solid, long-term support release. Pairing it with Django—one of the most popular Python web frameworks—gives you stability, security, and productivity. Perfect for everything from prototypes to production apps.
Prerequisites
Before you begin, make sure you have:
- A running Ubuntu 22.04.4 LTS server or desktop
- sudo privileges
- A basic understanding of the Linux command line
Step 1: Update Your System
sudo apt update && sudo apt upgrade -y
Keeping your OS packages up-to-date ensures you get the latest security patches and library versions.
Step 2: Install Python & pip
Ubuntu 22.04 ships with Python 3.10, but let’s install pip and venv:
sudo apt install python3-pip python3-venv -y
-
python3-pip: the Python package manager
-
python3-venv: built-in virtual environment support
Step 3: Create a Virtual Environment
Isolating your project dependencies avoids version conflicts:
cd ~
python3 -m venv my_django_env
source my_django_env/bin/activate
-
Your prompt will now show (my_django_env)
-
To deactivate later: deactivate
Step 4: Install Django
With your venv active, install the latest Django release:
pip install django
Verify the installation:
django-admin --version
Step 5: Start Your Django Project
Generate a new project scaffold:
django-admin startproject mysite
cd mysite
You’ll see:
mysite/
├── manage.py
└── mysite/
├── __init__.py
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
-
manage.py: CLI for running tasks
-
settings.py: central configuration
Step 6: Run the Development Server
Launch Django’s built-in server:
python manage.py runserver 0.0.0.0:8000
What’s Next?
- Create an app:
python manage.py startapp blog
- Configure your database (e.g. PostgreSQL) in
settings.py
- Add templates & static files
- Deploy to production with Gunicorn + Nginx
FAQ
Q1: Can I use Python 3.11 instead?
Yes, you can install via deadsnakes PPA, but ensure compatibility with Django’s supported versions.
Q2: How do I upgrade Django later?
pip install --upgrade django
Q3: Where are my static files?
Collect them via python manage.py collectstatic and serve with Nginx in production.
Conclusion
You now have a fully functioning Django project running on Ubuntu 22.04.4. From here, you can build apps, integrate databases, and deploy to production. Happy coding!