How to install a specific Python version on Ubuntu

It is often the case that we install a program on our system, and it turns out that it’s the wrong version. This can lead to compatibility and performance issues since it may not communicate with third-party modules properly. Similar is the case with Python, and as vigilant programmers, we must figure out the correct version that we need. Therefore, in this guide, we will show you how to install a specific version of Python on your Ubuntu system.

Python on Ubuntu

Usually, Python comes preinstalled in many Linux distributions. In our case, we have Python3. Start a new Terminal session through the Activities menu or by pressing Ctrl + Alt +T on your keyboard. To be on the safe side of things, you can check whether your distro has Python installed or not by running the following command.

$ python --version

Or, if you are running Python 3 like us, the command below ought to get the job done.

$ python3 --version

You can see in the image that the system is running Python 3.8.5. It is advised to upgrade your version of Python if you are running Python 3.3 or below. Stick around to find out more on which version you should get, as we will discuss that in the final segment of the article.

In the sections below, we will demonstrate how you can install any version of Python on your system, whether be it an updated one or an outdated one.

Installing a specific version of Python

The first step to installing Python is to install the necessary dependencies and packages that are required for its installation. However, to install these dependencies, you must have the multiverse repository enabled. You can enable it by running the command given below.

$ sudo apt-add-repository multiverse

Once that is out of the way, we move on to installing the first dependency. Run the command below to proceed.

$ sudo apt-get install build-essential checkinstall

It should finish downloading and installing in a few moments. Once it is done, move on to the next one by running the command below.

$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

It is a long and complicated command so simply copy-paste it into your Terminal to avoid any typing errors.

Having done that, we move on to downloading Python and installing it. For the sake of showing you how to install a specific version, we will be downgrading our Python from 3.8.5 to Python 2.7.

First, we change the current directory to the Downloads folder where we wish to download the package. This can be done by running the command below.

$ cd ~/Downloads/

The next step is to “wget” the package from the Python website.

$ wget https://ift.tt/3CfIq2g

Click here to access the location from where you can select any version of Python of your liking. All that needs to be amended in the wget command is the link.

Having successfully downloaded a specific version of Python, the final steps are simple and easy. First, we will extract the package through the command below.

$ tar -xvf Python-2.7.12.tgz

You can replace the version number as Python-version.tgz according to your package.

The next steps include opening the Python directory, configuring the files, and installing it. Run the commands below in the given order to proceed.

$ cd Python-2.7.12
$ ./configure
$ make
$ sudo checkinstall

The installation process, while it is straightforward and simple, should take a few minutes to complete. Once it’s done, you can check whether the installation was successful or not by simply running the commands we mentioned at the start.

As you can tell from the image, we have successfully downgraded from Python 3.8.5 to Python 2.7.12. You can do the same for any particular version of your choice.

Why you should install Python 3.5 or later

Now that we have covered the meat of the matter let’s talk about which Python version you should get and why.

Let’s start with the numbers. It makes sense that as time passes by, a utility or programming language progresses in terms of features and performance. Python 2.0 was released in 2000, Python 2.7 in 2010, whereas Python 3.0 was released in 2008, and Python 3.6 in 2016. The latest versions have more tools and libraries at your disposal, so it makes sense to use the later versions. However, it is understandable if you are trying to install an outdated version on purpose if some feature you need was removed later.

Python 2.0 is still used in many Linux systems as the default version. Some companies also use Python 2 for all their work. However, as the technology progresses, more and more companies are moving toward Python3. For instance, Instagram migrated its code-base from Python 2.7 to Python 3 in 2017. Similarly, Facebook is catching up and is upgrading its infrastructure to Python 3.4 and later.

Furthermore, Python 3 is easier to understand and learn for beginners. So if you happen to be just starting off with this programming language, it’s better to leave the veterans to the old ones and start your journey with a fresh and minted version of Python. In short, for those who haven’t already, consider upgrading your Python to version 3.5 or later.

Conclusion

In the modern era of computing, it is pertinent that we keep our systems updated, our software free of viruses, and our utilities upgraded to their latest versions. This way, we can make our daily tasks easier, simpler, and accurate. So being a programmer or developer helps to have the latest version of Python up and running on your system.



from Linux Hint https://ift.tt/3xn4c0u

Post a Comment

0 Comments