There are several ways to install Python on Linux if you need to install it at all!
Most Linux distributions include Python. Many will include both Python 2 and Python 3.
If you enter
python --version on the command line, you’ll see the version number. It’s probably version 2.7:
$ python --version Python 2.7.16
You don’t want Python 2, but some OS’es still ship with it, unfortunately.
python3 --version. If you get a “command not found,” you need to install Python 3. If your output looks similar to this, you’re in luck:
$ python3 --version Python 3.8.5
Depending on the distribution of Linux you are running, you can install Python with the default package manager: Yum, APT, etcetera. You’ll need to find out which package manager is used for your specific Linux distribution and how to use it.
If you’re on Ubuntu, Linux Mint, or Debian, you can install using apt:
$ apt install python3 python-is-python3
This also installs a package called
python-is-python3, which makes the command
python point to
python3. Trust me when I say it will save you a lot of headaches later on.
Another interesting option for Linux is using Homebrew. That’s right, the package manager for Macs also works on Linux.
The major advantages of using Homebrew:
I find myself using Homebrew more and more while working under Linux — give it a try!