How to Install Python 3 on Linux (Ubuntu / Fedora / CentOS…)
In the previous article, I have described all the steps to be followed to install Python on 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…
- Python 2 (Latest version – 2.7.13)
- Python 3 (Latest version – 3.6.2)
In this tutorial, I will be covering 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 installation…
You can download Python package from their official website. Or you can skip downloading it if you have internet connected 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.
Install Python on Linux:
To install any package on Linux, you need to use specific command based on the package manager.
APT package manager – Debian / Ubuntu | Linux Mint Linux User
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).
DNF Package Manager – Fedora Linux User
Fedora have 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.
Yum Package Manager- Redhat / RHEL / CentOS Linux User
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.
You installed Python successfully.
Interestingly, you can download both Python 2 and Python 3 version on your single system.
Checking Installed Python:
Open Linux terminal and type…
It opens Python 2 version interpreter prompt.
It opens Python 3 version interpreter prompt.
You can write your Python code in Python interpreter prompt.
Do you want to check Python version installed on your system?
Run a command…
Writing Hello Wolrd Program on Python Prompt:
To test if the Python is working fine, write your first hello world program on Python interpreter prompt.
print "Hello, World!"
Wow! It is so easy.
To exit Python interpreter prompt, run following command.
exit() or quit()
and press Enter.
Related Read: How to Clear Python Interpreter Console?
Now everything is setup to start harnessing Python skills. If you are eager to learn Python, follow Python tutorial from the beginning.
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!