How to install Django on a CentOS 7 VPS or Dedicated Server

When building a website, similar components are required, and you do not have to reinvent the wheel every time you build a new website. Django is the tool you require for this.

In this article, various methods of installing Django are covered and how to create your first project.

Special note: consult HostAdvice's Best Django Hosting page to find the leading web hosts in this category, including expert and user reviews.

Overview

Django is a powerful tool for writing web applications. Using Django framework is the easiest way to make an idea a business reality. It makes sure you have as fewer hassles as possible while you are creating your web applications. It has dozens of features such as user authentication and RSS feeds and is very secure. So let's see how to install Django on a CentOS

Installation of Django

Django installation is done in several ways, and we shall cover a few of them in this article. They all rely on the EPEL repository for CentOS and RedHat like distributions. The EPEL repository contains extra packages not found in the core distribution. To use EPEL, type yum command to configure the use of EPL repository;

sudo yum install epel-release

Below are some of the methods of installing Django;

  • Installing from packages
  • Installing through pip
  • Installing through pip in a virtual environment
  • Installing the development version through git

Installing from packages

We use the yum package manager to install Django packages from the EPEL repository. The drawback is that the version contained in EPEL may not be the latest one. However, this process is straightforward, type the following:

sudo yum install python-django

To verify installation:

django-admin --version

If successful it should show:

1.6.0

Installing from pip

If you would like to install the latest Django, this method is for you. We first install the pip package manager and then install Django. So type the following;

sudo yum install python-pip

Next, you can now install Django by typing:

sudo pip install django

Now to check if the installation was successful:

django-admin --version

If successful, it should show you the following;

1.7.5

Note that the version in pip is more up to date than the one from EPEL.

Installing through pip in a virtual environment

Use the Virtualenv tool to create virtual environments. It is in these virtual environments that python packages are installed without affecting the rest of the system. It is useful if your projects tend to conflict with other different projects.

First, is to install pip from the EPEL repository.

sudo yum install python-pip

With pip installed, we can now install the Virtualenv package;

Installing through pip in a virtual environment

Now each time you start a project you have to create a virtual environment for it. So we are going to set a new project category:

mkdir ~/newproject
cd ~/newproject

Next, create a virtual environment by typing;

virtualenv newenv

Note: newenv >is just a name; you can choose whichever name you want.

The above command installs python and pip into the virtual environment. To install packages in our virtual environment, just type;

source newenv/bin/activate

Your command line should change and look like the following;

(newenv)username@hostname:~/newproject$

Now install Django using pip;

pip install django

To verify the installation, type;

django-admin --version

It should show;

1.7.5

If you wish to leave your environment type deactivate;

deactivate

To restart, type the following;

cd ~/newproject
source newenv/bin/activate

Installing the development version through git

This method installs the latest development version. It requires us to get the Django code directly from the git repository. Install git and pip on our system using the >yum command;

sudo yum install git python-pip

Clone the repo to a directory called django-dev.

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

The repository can now be installed using pip. We will use the –e option to install in editable mode.

sudo pip install -e ~/django-dev

We are now set to verify the installation. To do so just type,

django-admin --version

If it has installed successfully, it should show;

Conclusion

We have gone through a few ways for you to install Django on your CentOS 7 machine. Depending on your choice of installation, you can get fresh new features for the development version, or you can get the most stable version.  So each installation has its disadvantages and advantages. We certainly hope you get to enjoy the many features of Django firsthand.

 

Check out the top 3 Dedicated server hosting services:

Was this article helpful?