3 Ways to install Python 3 on Ubuntu 18.04 Linux.


In this tutorial, we will cover “How to install Python 3 on Ubuntu 18.04 LTS in 3 ways”. python2 and python3 already come with the Ubuntu 18.04.

You can check your python version by using “python –version” or “python3 –version”. After the installation, we can run a source code for python.

Python is a high-level, interpreted programming language. Now Python is the most important for Machine Learning and Data Science.

Python is one of the most popular languages over the globe. You can use Python for Web, GUI, and Software Development. The System administration tools like Ansible, Salt and OpenStack are in Python.

So let’s look at the 3 ways to install Python 3 on Ubuntu 18.04 LTS.

  1. Install Python 3 using apt command.
  2. Add Repo and Install Python 3.
  3. Install Python 3 with source code.

How to Install Python 3 using apt command.

So to install, this is the easiest method, we have to update the repository and install the package. These Python packages are the official from the Ubuntu repositories.

$ sudo apt update

We have updated the repository present in the Ubuntu 18.04.

$ sudo apt install -y python3

Once installed you can verify the version for Python using the below command.

$ python3 --version

Python 3.8.10

How to Install Python 3 by adding repository.

If you are not able to install with the above method. Then you try adding the deadsnakes repository on the Ubuntu system. But before that, we have to install the package named as “software-properties-common”.

$ sudo apt install software-properties-common -y
$ sudo add-apt-repository ppa:deadsnakes/ppa

So it will prompt on the terminal “Press [ENTER] to continue or Ctrl-c to cancel adding it.”. We will press “Enter” to continue and it will add and update the repo.

$ sudo apt install -y python3

Once installed you can verify the version for Python using the below command.

$ python3 --version

Python 3.8.10

How to Install Python 3 by Source code.

So let’s download the latest version of python from the official website. After downloading into the local system compile the source code. But before that, we install the dependencies packages using the apt command.

$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget -y
$ mkdir python-setup && cd python-setup

So let’s create a folder named as “python-setup” in this folder. As we are going to keep the source code for Python.

Now let’s go to the official website and check the new version to install in your system.

Image of Python version to be install in the system.

Click on the version you have to install in my case I have selected version 3.9.9 and download the .tgz file.

Download the highlighted version for python in local system.

So right-click on the file and we can see “Copy link address” and use the wget command to download.

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

--2022-06-08 11:48:55--  https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz
Resolving www.python.org (www.python.org)..., 2a04:4e42:24::223
Connecting to www.python.org (www.python.org)||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25787134 (25M) [application/octet-stream]
Saving to: ‘Python-3.9.9.tgz’

Python-3.9.9.tgz                                  100%[===========================================================================================================>]  24.59M  4.35MB/s    in 5.6s    

2022-06-08 11:49:01 (4.38 MB/s) - ‘Python-3.9.9.tgz’ saved [25787134/25787134]

So the file got downloaded, let’s extract the files using the tar command.

$ tar -xvf Python-3.9.9.tgz

Once the extraction will complete you will find the folder. you can use the ls command to check the folder name.

$ ls 

Python-3.9.9  Python-3.9.9.tgz

Go to the folder and execute the ./configure file.

$ cd Python-3.9.9/

$ ./configure

So this will check all the required packages to install the Source code. Then compile your source code with “sudo make install”.

$ sudo make install

It will take around 4 to 5 minutes. Once the Source code gets installed then use “python3.9” to verify the version.

$ python3.9

Python 3.9.9 (main, Jun  8 2022, 11:59:18) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.


So this tutorial helped us to install Python 3 in Ubuntu 18.04 LTS in 3 different ways. The 1st method installs with the official Ubuntu repository. 2nd method to install with the deadsnake repository. And the last method installs with the Source code. If you find any issues while installing python we will happy to help you out. Any feedback leaves a comment.

Give your valuable time