How To Install Python In Ubuntu
How To Install Python In Ubuntu
Ubuntu is free and open-source software and it is an essential part of the Linux distribution.
It is a popular operating system developed by Canonical.
If we start counting the strengths of Python, we can make a long list in which each pointer would speak for itself and that's why Python is unabashedly the most used language by the developers.
Since we all know that python is compatible with all the platforms, let’s understand how does it work on Ubuntu.
So, here we will discuss the steps that we should follow and some pre-requisites that we must have to install Python in Ubuntu.
Let’s quickly understand the steps so here we go-
- The first step here is to ensure that the list of packages is updated or not, which can be checked by writing the following command-
sudo apt update
- Once the packages are updated, the other essential thing is to have an idea about the pre-requisites which can be verified using-
sudo apt install software-properties-common
- The next step here is to add deadsnakes PPA to our sources list.
Here one question that would strike in the mind of readers that what is 'Deadsnakes PPA'
So the answer for the same is that Deadsnakes PPA(Personal Package Archive) allows us to install multiple versions of Python in Ubuntu.
This particular thing can be implemented using the command-
sudo add-apt-repository ppa:deadsnakes/ppa
- Once we found out that the repository is enabled now, we can initiate the installation process with the command given below-
sudo apt install python3.8
- So finally, we have reached the stage where Python has been installed in Ubuntu successfully, if we again want to cross-check or verify its version, this can be done by writing the command given below-
python –version
The second method to install Python in Ubuntu is explained as follows-
Installing from source
- The first thing is to update the list of packages and install the ones which are important for building Python source-
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm -dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev
- The next step is to download the latest version of Python from its download page using wget command
wget (Add the address of the latest version, you can obtain it from Python’s download page).
- When the download process is completed, the next step is to extract the gzipped tarball:
tar -xf Python-3.7.4.tgz
- The next thing to implement is running the configure script so that it can perform the required number of checks to ensure that all the necessary things on our system is present.
cd Python-3.7.4
./configure –enable-optimizations
- So now what we have to do is to start the python build process using make:
make -j 8
If you want your build time to be faster, you can adjust the -j flag on the basis of your processor.
The number of cores in the processor can be found by typing nproc.
- Now we are done with the building process, next, we will install the python binaries with the help of commands written below-
sudo make altinstall
- Finally, here we have successfully installed Python version 3.7.
- The installed version can be verified using-
python3.7 –version
- The output that will be displayed on our screen would be like-
Python 3.7.4
So, hope we all have understood by now that how one language can help us to learn multiple things, It’s features always keep us on the track of enlightenment. We are all set now to work with Python in different operating systems.
We started with some very simple topics and then took a step ahead and stretched our boundaries of learning. We took a deep dive into the various approaches to run a program in Python. Then we looked at the different ways of taking input in Python.
Different IDEs, n number of libraries and tools, and the application and discoveries that we never thought were feasible.
Python has wrapped some interesting features in it and that’s why it is in great demand. So, keep learning and exploring. There are still a lot of things you have to learn.
In our next section, we will learn about the pip command.