Python is one of the most widely used programming and scripting languages. With the use of the Internet of Things (IoT) & Artificial Intelligence (AI) on the rise, python has become one of the most widely sought computing languages. Python is a high-level programming language used for general-purpose programming.
Python emphasizes on code readability & is very easy to pick up & learn. Moreover, there is a very active community for python & you can start from thousands of projects available for free depending on your use-case.
Recommended Read: How to change timezone in Linux
Also Read: How do i install Tomcat 9 on Ubuntu ???
Python support for versions 2 aka python 2 has been discontinued from 1st Jan, 2020 & now only python version 3.5+ will be supported. In this tutorial, we will learn to install Python from source on Linux systems. Let’s start with system pre-requisites first,
We must have packages for all build tools installed on our system, most of the time they are pre-installed but we can make sure by running the following command,
CentOS/RHEL (Amazon Linux, Oracle Linux)
# yum -y groupinstall development
# yum -y install zlib-devel
Ubuntu (Mint, Debian)
$ 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
Once these tools have been installed, we can move on to install python from source.
Install Python from source
We will be installing python stable version 3.7.6 in this tutorial, so let’s download tar file for python 3.7.6,
# wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
Once it is downloaded on the system, extract it,
# tar -xvf Python-3.7.6.tgz
# cd Python-3.7.6
Now we will run configure to prepare the build,
# ./configure –enable-optimizations –with-ensurepip=install
Next step would be to compile it,
NOTE:- Before you run the next command, please read this. You should the next command i.e. “make altinstall” & DONT USE “make install”, as ‘make install’ will cause your system’s python binary files to be overwritten & that can be catastrophic for your system. I REPEAT DONT RUN ‘make install’.
Now, we can install python with the following command
# make altinstall
That’s it now, once this command finishes, python 3.7.6 will be installed on your system. You can check the version with,
# python -V
We end this tutorial on how to install python from source. Please do send in any questions, queries or suggestions using the comment box below.