There are many web applications which are made up of long and complicated codes. Due to these lengthy codes, it takes a long time for a web application to be launched, this issue is resolved by Django. Now, you can create your own web applications with simple and less code using Django, it will make your web applications more efficient.

What is Django?

Django is an open-source Python framework for the web, so anyone can access Django in web development and build web applications from the level of simple to complex applications quickly. Django is fully loaded with tools that are useful for the developers in web application development, such as user authentication and RSS feeds. Django is scalable, therefore, many famous websites are using it as it can handle heavy traffic easily as well as it provides the full security proof plans to manage user accounts and passwords.

In this guide, we are going to explore the installation methods of Django on the latest release of Ubuntu Jammy Jellyfish using the command-line interface.

How to install Django on Ubuntu 22.04

There are two methods to install Django on Ubuntu which are listed below:

  • Through the default repository of Ubuntu
  • Through the Git repositories

Both the methods are explained in detail in the next sections of this guide.

Method 1: Installing Django on Ubuntu through default repository of Ubuntu

This is the most convenient method to install any packages on Ubuntu, so we will first update all the available packages on Ubuntu repository by using the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-1.png" data-lazy- height="317" src="data:image/svg xml,” width=”1102″>

After updating, we will confirm the installed Python version using the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-2.png" data-lazy- height="131" src="data:image/svg xml,” width=”640″>

Then we will use the apt package manager to install the package of Django from default repository:

$ sudo apt install python3-django -y

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-3.png" data-lazy- height="444" src="data:image/svg xml,” width=”1247″>

To validate the installation, we will check the version of installed Django using the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-4.png" data-lazy- height="114" src="data:image/svg xml,” width=”753″>

To remove this installed package of Django use the purge command:

$ sudo apt purge python3-django -y

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-5.png" data-lazy- height="552" src="data:image/svg xml,” width=”1206″>

Method 2: Installing Django on Ubuntu through Git repository

The other method to install Django is downloading it from Git repository, for this, we have to install the pip and python management packages by using the command:

$ sudo apt install python3-pip python3-venv -y

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-6.png" data-lazy- height="409" src="data:image/svg xml,” width=”1270″>

Now we will clone the directory of Django from the git repository to our home directory using the command:

$ git clone https://github.com/django/django.git ~/django-dev

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-7.png" data-lazy- height="276" src="data:image/svg xml,” width=”1209″>

Navigate to the cloned directory using the cd command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-8.png" data-lazy- height="95" src="data:image/svg xml,” width=”927″>

Before the installation of Django, we will create the virtual environment “LinuxHint_env” for the Django and also activate the virtual environment “LinuxHint_env” using the command:

$ python3 -m venv LinuxHint_env && source LinuxHint_env/bin/activate

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-9.png" data-lazy- height="112" src="data:image/svg xml,” width=”1283″>

Now with the help of pip, we can install Django:

$ pip install -e ~/django-dev

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-10.png" data-lazy- height="488" src="data:image/svg xml,” width=”1242″>

Check the version of installed Django using the command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/2-Easy-Methods-to-Install-Django-on-Ubuntu-22.04-11.png" data-lazy- height="115" src="data:image/svg xml,” width=”1071″>

Conclusion

Django is a framework for the web developers to build web applications with the code of a few lines so the launch time of the application can be reduced. In this guide, we have explored two different methods of installing Django on Ubuntu, one is from its own repository, and the other is from the git repository.

About the author

<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/hammad–150×150.jpg6293dcdcd5d2d.jpg" height="112" src="data:image/svg xml,” width=”112″>

Hammad Zahid

I’m an Engineering graduate and my passion for IT has brought me to Linux. Now here I’m learning and sharing my knowledge with the world.