How to Install Python 3 on Ubuntu 18.04 or 20.04 {Step-by-Step}

By | September 27, 2021
How to Install Python 3 on Ubuntu 18.04 or 20.04 {Step-by-Step}

Python is one of the widely used programming languages. It has a very simple and easy to learn syntax which makes it popular amongst beginners and advance developers. Python has many libraries for all the levels of Python developers, and it can be used for web development, machine learning, and Data Science.

Python is a cross-platform programming language which means it is supported by all the popular Operating Systems, including Linux Distro. Most of the Linux Distros and macOS come with pre-installed Python3 latest stable version, however, there are some Linux distros which does not come with the pre-installed Python but it presents in Universe repository.

Here in this article, we have mentioned the steps and terminal command to install Python3 on Ubuntu 18.04, Ubuntu 20.04, and above.

Perquisites to install Python3 on ubuntu 18.04, 20.04 and above

  • Ubuntu 18.04 or Ubuntu 20.04
  • User logged in as a Root user with sudo access.
  • Internet connection

How to install Python3.8 version on Ubuntu 18.04, 20.04 and above

Python3.8 and above do not come pre-installed in Ubuntu 18.04 and Ubuntu20.04. If you are using 18.04 and above version of Ubuntu then either an old version of Python will be installed in your system or there would be no Python installed. However, the Python would be available in the universal repository.

The installation process of Python3.8 and above in Ubuntu18.04 and Ubuntu 20.04 is similar. And there are two approaches you can follow to install Python3.8 in your ubuntu Linux distro.

Vamware
  • Install Python on Ubuntu from a package manager using apt command
  • Install Python on ubuntu from the build source code.

Install Python3 on Ubuntu 18.04, Ubuntu 20.04, and Above with apt

It is the simplest way to install Python on any Linux distro system like ubuntu or mint. Using the Linux Package manager, we can install python from the terminal command using the apt command. Follow the steps given below

Step1(optional): The first step is Update the packages, if your all packages are already updated then skip to step 2

Vamware
$ sudo apt-get update

Step2: install Python 3 with apt install command, 

$ sudo apt install python3.8

this will take some time and python 3.8 will be installed in your system.

Step3: install pip for the python3.8, you also need to install the pip command.

$ sudo apt install python3-pip

Step4: Verify whether the Python and pip installed in your system or not. To verify the version of the installed python and pip use the python -Vand pip command.

Install Python3.8 on Ubuntu 18.04 and 20.04 from Pythons build source code

This technique of installing python is a bit complex than apt method. You can use this method of installing Python3 on a ubuntu system if Pytho3 is not available at Universe Repository.  

Follow the step given below to install Python 3.8 on ubuntu from the source Code.

Step1: Update the package list and install all the dependencies to build Python source.

$ sudo apt update
$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev

Step2: Download the Python latest version source code official website using wget command.

wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz

Step3: Extract the download python gripped tarball file using tar command

$ tar -xf Python-3.8.3.tgz

Step4: Navigate to the python software

$ cd python-3.8.3

step 4: Before installing the file, configure it to optimization and it will lead to better code execution by 10-20%.

$ ./configure ––enable–optimizations

Step 5: Now install the python binaries using make altintall or make install command.

$ sudo make altinstall

or

$ sudo make install

the make altinstall will install the new version of python3.8 and will also keep the python3.7 if installed.

The make install command will replace the python 3.7 with pytho3.8 if python3.7 or old python version was already in the System.

Step6: verify python version

use the command python3 -V to check the installed Python version.

Conclusion

Here in this tutorial, you learned How to Install Python 3 on Ubuntu 18.04 or 20.04. The easiest way to use the ubuntu package manager apt to install the latest version of Python. You can also download the Python source code from the official website of the python and install it in your Ubuntu system.

People are also reading: 

Author: Vinay

I am a Full Stack Developer with a Bachelor's Degree in Computer Science, who also loves to write technical articles that can help fellow developers.

Leave a Reply

Your email address will not be published.