Python is an interpreted high-level general-purpose programming language. It's design philosophy emphasizes code readability with it's use of significant indentation. It's language constructs as well as it's object oriented approach aim to help programmers write clear, logical code for small and large-scale projects.
Most of the times the Ubuntu version 18.04 and 20.04 come with Python pre-installed. You can use the below command and run it in terminal to check if Python is installed already on your system.
python --version
If version comes out to be lower than 3 or if python is not installed, please proceed to next steps.
Step 1: Update repository list
Run this command to update the repository list.
sudo apt update
Step 2: Install dependencies
Run this command to install packages that are required for Python to work properly.
sudo apt install software-properties-common
Step 3: Install Deadsnakes PPA
Deadsnakes is a PPA with newer releases than the default Ubuntu repositories. Add the PPA by entering the following:
sudo add-apt-repository ppa:deadsnakes/ppa
Once this finishes, please refresh the apt packages again by running the command.
sudo apt update
Step 3: Install Python
Now we are good to go and install python. You can install python by running this below mentioned command.
sudo apt install python3.8
Once this is installed, we can confirm by checking the python version again using::
python --version
This must have an output as `Python 3.8.2`.
Step 1: Update the apt package repository
sudo apt update
Step 2: Next install the dependency packages required for Python to build
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev
Step 3: Download the latest Python package, using the wget command.
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
Step 4: Once the zip is downloaded, we would need to unzip it. We can do it using below code.
tar -xf Python-3.7.4.tgz
Step 5: Check and install required dependency for Python to run
cd Python-3.7.4 ./configure --enable-optimizations
The --enabled-optimizations flag will optimize the Python binary by running multiple tests, this might make the build process slower.
Step 6: Start the Python build process
make -j 8
Step 7: Install Python Binaries
sudo make altinstall
Step 8: Verify the installation
python3.7 --version
Conclusions
Now we have Python 3 installed on your Ubuntu system.