Skip to main content

CHAKRAPANI GAUTAM

About Me

Install Python3 on CentOS/RHEL and Fedora

Comments
Install Python3 on CentOS/RHEL and Fedora


Working with Python on Linux isn't as spooky as you think. It's just the same as any other programming language that it supports and it's actually fun. You might be wondering how come we work on Linux with that big black screen in front of us. Well, in that case, you would love to check this post out.

Linux distributions are known for having an enormous collection of software packages, and Python is one of them. A simple application on Linux, say a Calculator, requires the support of multiple programming technologies. And to prepare the system to run those applications flawlessly, most of the distributions are prepackaged with different programming environments; like C, C++, Java, PHP, Python etc. So no typical installation is required.


"Then what the heck is this post all about?"

Well, this post is for those who want to play with the latest version of Python without damaging the previous one. It is usually Python 2.7.x on most of the systems to provide backward compatibilities to the applications because they were written way before Python3 was released. But if you're OKAY with your default Python installation, you can skip this post and start with your first Python script.

Now those of you who are still with me, I would like to mention that these steps for installation are typically for RedHat distributions like Fedora, CentOS etc. But you can try them on others as well. All you need to do is to change the default package manager to yours. Like if you're using Ubuntu, you need to change dnf to apt-get in all your commands. And that's it!

So here we go.

Step 1: Install required packages

Use the following command to install the prerequisites for Python.
$ sudo dnf install gcc
This command will install a package called "gcc" which is acronym GNU C Compiler. Why? Well, I would recommend having a quick tour of various Python implementations.

Step 2: Download Python 3.6

Download the package from the official website for the latest version of Python, or type in the following commands.

$ cd /usr/src
$ wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

Now extract the downloaded package.

$ tar xzf Python-3.4.8.tgz

Step 3: Compile the Python source

It is the most crucial part of the installation. Execute these commands to compile the source and install it on your system.

$ cd Python-3.6.5
$ ./configure --enable-optimizations
$ make altinstall

make altinstall is used to prevent replacing the default python binary file in /usr/bin/python

Now after installation, remove the source archive from your system.

$ rm Python-3.6.5.tgz

Step 4: Confirm the installation

And finally, you can check whether the installation was successful or not.

$ python3 --version
Python 3.6.5

Mission accomplished!


I hope you would've found this post interesting and worth reading. If you've any queries or suggestions for this post, please mention them in comments below.

Happy Programming!

Thoughts

Comments