How to install Python 3.x on Linux?


Gaming Laptop Series

Python is one of the most popular, general-purpose programming language. It emphasizes more on code readability so its syntax is simple and easy to use. It is used widely for desktop or web app development and fields such as data analysis and visualization, AI, and machine learning.

There are two major versions of python i.e. Python 2 & 3. Python 2 is no longer developed while Python 3 fixes many problems that were in Python 2, nowadays Python 3 actively used for new projects.

As of now Python 3.9 is the latest stable release of the python programming language. We will see how to download and install it on a Linux system.

Installing Python 3.x on Ubuntu, Linux Mint from OS repository

By default Python, 2.x and 3.x come preinstalled on most of the Linux distributions but if it is not in your system you can use the following commands to install on an apt-based Linux distribution which includes distributions such as Ubuntu, Linux Mint, Kali Linux, etc.

First, check update and upgrade packages on your system by using –

sudo apt update

and then use –

sudo apt -y upgrade

Now check if your system already have Python 3 installed –

python3 --version

If Python3 is installed you will see the current version of it otherwise you will see command not found message –

To install the latest version of python3 use the given command –

sudo apt install python3

This will download and install the latest available version of Python 3 in the operating system.

How to install Python 3.x from the source

To install the latest version of Python 3 from its source you need to download the source code of python from the download page on its official website. You can use the following command to download the latest version of Python 3 on your system –

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

You need to prepare a few things before you install python from the source.

First, update and upgrade all the packages on your system by using –

sudo apt update && apt upgrade 

On CenOS/RHEL use –

sudo yum update && apt upgrade

Next, make sure you have installed all the build requirements on your system.

Use the following command on apt-based systems such as Ubuntu/Linux Mint –

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
       libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
       libncurses5-dev libncursesw5-dev xz-utils tk-dev

Or if you are using a yum based distribution such as CentOS/RHEL then use –

sudo yum -y groupinstall "Development Tools"
sudo yum -y install gcc openssl-devel bzip2-devel libffi-devel

Now extract the downloaded tarball using –

sudo tar xvf Python-3.9.1.tgz

Move to the extracted python directory

cd Python-3.9.1

Prepare the build using –

./configure

Finally use –

make

make install

You can verify the installation by running the given command.

Python3 -v

Conclusion

You have successfully installed Python 3 latest version on your system. If you find any difficulty while installing then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.