How to Install Django Web Framework in Ubuntu 22.04?

By Hardik Savani May 1, 2024 Category : Ubuntu

In this post, our main focus lies in guiding you through the process of installing Django on Ubuntu 22.04. If you're seeking an illustrative example of how to perform this installation within the Ubuntu terminal, you've landed in the correct spot. Here, you'll grasp the fundamental concept of installing Django on Ubuntu 22.04. This serves as a straightforward instance of how to carry out the Django installation within the Ubuntu 22.04 environment. Without further ado, let's delve into the intricacies of the procedure.

To install Django Web Framework on Ubuntu 22.04, follow these step-by-step instructions:

Step 1: Update System Packages

Open the terminal by pressing Ctrl+Alt+T and update the system packages using the following command:

sudo apt update

Step 2: Install Python and pip

Check if Python is already installed by running python3 --version. If it's not installed, run the following command to install Python:

sudo apt install python3

Then, install pip (Python package installer) using the package manager:

sudo apt install python3-pip

Step 3: Create a Virtual Environment

In order to keep Django and its dependencies isolated from other Python projects, create a virtual environment. Run the following command to install the venv package:

sudo apt install python3-venv

Next, create a virtual environment using the venv package:

python3 -m venv myenv

This command will create a directory named myenv as the virtual environment.

Step 4: Activate the Virtual Environment

Activate the virtual environment using the following command:

source myenv/bin/activate

You will notice that your terminal prompt now starts with (myenv).

Step 5: Install Django

With the virtual environment active, use pip to install Django:

pip install django

This will download and install the latest version of Django.

Step 6: Verify Django Installation

You can verify the installation by running the following command to check the Django version:

python -m django --version

If Django is correctly installed, it will display the installed version.

Step 7: Start a New Django Project

Create a new Django project using the following command:

django-admin startproject myproject

Replace "myproject" with the name you want to give your project.

Step 8: Run the Development Server

Change to the project directory:

cd myproject

Finally, start the Django development server using the following command:

python runserver

This will start the server at Visit this address in your browser, and you should see the default Django welcome page.

Congratulations! You have successfully installed Django Web Framework on Ubuntu 22.04 and started a new project.

I hope it can help you...

Tags :