In order to install Django on any operating system, we need to already have python and pip installed. If you have not, please install python3 and pip3 on Ubuntu.
Now, I assume that you already have python and pip installed on your Ubutnu 18.04. Let’s install Django 2.1.7 which is the latest version at the moment.
To make our app development and deployment easier, we must create python virtual environment, so, let’s create virtualenv and activate it. To install python virtualenv, launch your terminal and run the following command.
Run the following commands…
pip3 install virtualenv
Once virtualenv is installed, we need to create and activate python virtualenv in user’s home directory. You can create it wherever you want it to be, but I like to keep it in my home directory. Please run the following command with terminal.
python3 -m virtualenv env_name
Let’s activate our env_name
Now, we are in the python3 virtual environment, we can install the Django framework and create our very first project. Run the following command.
pip3 install django or pip install django
From python virtualenv, you can execute pip3 and python3 with pip and python. Because, this environment has to nothing to do the with Ubuntu.
To link all the installed python packages
It is good practice to create a dedicated directory for our Django applications. So, let’s create a our project directory in the same directory, where the virtual environment is created.
After creating the directory and changing the directory, we can create our first Django project and run the server… Let’s do that
django-admin startproject project_name
python manage.py runserver