How To Install Django on Centos 7

In this guide, we intend to teach you How To Install Django on Centos 7.

Django is a free and open-source web application framework, written in Python. A web framework is a set of components that helps you to develop websites faster and easier.

When you’re building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc.

Luckily for you, other people long ago noticed that web developers face similar problems when building a new site, so they teamed up and created frameworks (Django being one of them) that give you ready-made components to use.

Frameworks exist to save you from having to reinvent the wheel and to help alleviate some of the overhead when you’re building a new site.

Install Django Web Framework on Centos 7

To install Django, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Centos 7.

There are several ways to install Django on a Centos machine.

  • Install from yum packages
  • Install through pip
  • Install through pip in a virtual environment
  • Install from Git

In this guide, we will install Django with pip in a virtual environment.

Installing Django on Centos 7

As you know, Django is written in Python, so you should have Python installed on your server. Centos has Python 2 in its yum repository. To install Python 3 on your server, you can follow our guide on How To Set up Python 3.10 on Centos 7.

Install pip on your server:

sudo yum install python3-pip

Once pip is installed, you can use it to install the virtualenv package by typing:

sudo pip3 install virtualenv

At this point, you can create a virtual environment to start your new project. Create your project directory with the following command:

mkdir ~/newproject

Switch to your project directory:

cd ~/newproject

Now inside your project directory, create a virtual environment by using the below command:

virtualenv newenv

Next, you need to activate your virtual environment with the following command:

source newenv/bin/activate

Your prompt should change to reflect that you are now in your virtual environment.

In your virtual environment, use pip to install Django on your server:

pip3 install django

You can verify your Django installation on Centos 7 by running:

django-admin --version
Output
3.2.14

To leave your virtual environment, you need to issue the deactivate command from anywhere on the system:

deactivate

For more information, you can visit the Django Documentation page.

Conclusion

At this point, you can Install Django on Centos 7.

Hope you enjoy using it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!