In the previous article, I have described all the steps to be followed to install Python on the Windows system. In this article, I am sharing all the commands you should run to install Python on Linux, including various Linux distributions.
There are two major Python versions…
In this tutorial, I will be covering the installation of both versions.
To update you, many of the giant companies are moving to Python 3. In recent, Instagram is migrated from Python 2 to Python 3, successfully.
So coming to the installation…
You can download Python package from their official website. Or you can skip downloading it if you have internet connection to your Linux system where you want to install Python.
As we all know, there are various flavors of Linux such as Ubuntu, Fedora, Linux Mint, CentOS… And each one of the Linux distribution has a particular package manager.
Depending on the package manager, you need to follow commands to install Python on Linux.
Let’s see how to install Python on each Linux distribution, individually.
Table of Contents
To install any package on Linux, you need to use a specific command based on the package manager.
There are different package manager used by the different Linux distribution.
Based upon type of Linux distribution you are using, check the following commands to install latest Python version.
Ubuntu and Linux Mint distributions use APT for package management.
To install Python in these Linux distribution, Open terminal and run command those are given below.
$ sudo apt-get update $ sudo apt-get install python3.6
If you want to install Python 2 version, run following commands…
$ sudo apt-get update $ sudo apt-get install python2.7
Note: There can be multiple dependencies among packages installed on Linux. Make a habit of updating installed packages before installing any new package (First command mentioned above).
Fedora has a default DNF package manager for installing and managing packages in Linux.
Run following command in terminal.
Installing Python 3:
$ sudo dnf install python3
Installing Python 2:
$ sudo dnf install python2
It installs the latest Python version for both Python 3 and Python 2.
Redhat / RHEL / CentOS Linux User should run the following command to install Python.
$ sudo yum install python
If you are not root user, you should use sudo
keyword every time installing Python package on your Linux system.
Meanwhile, you can have coffee for you as it may take some time to install.
That’s all!
You installed Python successfully.
Interestingly, you can download both Python 2 and Python 3 versions on your single system.
Open Linux terminal and type…
python
It opens Python 2 version interpreter prompt.
python3
It opens Python 3 version interpreter prompt.
You can write your Python code in Python interpreter prompt.
Do you want to check the Python version installed on your system?
Run a command…
python --version
To test if the Python is working fine, write your first hello world program on Python interpreter prompt.
print "Hello, World!"
Output:
Hello, Wolrd!
Wow! It is so easy.
If you are new to the Python, check the basic Python coding syntax.
To exit Python interpreter prompt, run the following command.
exit() or quit()
and press Enter
.
Related Read: How to Clear Python Interpreter Console?
What’s Next?
Now everything is set up to start harnessing Python skills. If you are eager to learn Python, follow Python tutorial from the beginning.
Remember…
You can not learn any programming language without making your hands dirty with the code.
To install Python on Linux system, you need to follow these commands. If you face any issue to install Python on Linux (Ubuntu or any Linux distribution) or any comment for this article, write in the comment section. Let’s connect with us.
All the Best!
Python 2.7.x is already installed on Linux(Ubuntu or CentOS). how we can install python 3.x on linux if python 2.7 already install ?
You can use Python Virtualenv. With this, you can create as many virtual environments and installing different Python version.
Hi, how can use Python Virtualenv? Do I need to download it? My Linux system has 2.7. I have download 3.9 in my Linux system but not sure how to upgrade my version.
Thanks in advance for your help.
Hi Showeb, you can keep both versions Python2 and Pyhton3. Regarding virtual environment, latest Python 3 comes with an inbuilt module called “venv”. You can use it for creating a virtual environment. You don’t need to download and install it separately as it comes inbuilt with Python installation.
Hi myself Meena. I installed python 3.6 in Linux ubuntu 14.04. If I will check python version by python –version it is showing default python 2.7.6.
I want to write scripts using vim editor and trying to execute using Python version 3.6
Can anyone help me how to set to the Python default path to V3.6?
Hi Meena, Use “py” instead of “python” while executing Python script. It will execute Python script using Python 3 version.
I would like to take this opportunity to thanks in especial Aniruddha highlighting key notes from my personal experience.
As we all know and experience, we do have many sources for knowledge already available, Important is what to do if we get stuck in between?
Aniruddha is so kind as to help us even at small step giving solutions as well as Encouraging the reader to reach his/her Goal.
This is a lot to me. Thanks a lot, Aditya. Your words keep me motivated.
I’m new to programming and I am using Linux for Python coding. What do you prefer to learn coding- Mac or Linux?
You are already going good. Continue with Linux.