Lesson 2
The Basic Elements
Chapter 2: Installing Python
Installing Python on Unix/Linux
You can skip straight to the next page if you are not using Unix/Linux.
Most Unix/Linux-based Operating Systems nowadays should already come with a version of Python, known as the system installation. The system installation of Python is very rarely the most up-to-date available version of the language.
Type this into your terminal window to check the Python version of the system installation. It is likely to be Python 2 (which is no longer officially supported) if you are using an older version of Linux, e.g.\ Ubuntu 20.04.
$ python -V
Don’t try to upgrade or mess with this installation - you might break your operating system if you do not know what you are doing! Some parts of your operating system might rely on this particular installation!
Your Unix/Linux operating system might also come with a Python 3 installation. For example, Ubuntu 22.04 should already come with Python 3.10. Type the following to check.
$ python3 -V
If the version is at least 3.10, then perfect! You do not need to do anything more.
If the version is less than 3.10, then you might want to install your own user installation of Python 3.10 alongside this version, because again there is a risk of this version of Python being needed for something else if you upgraded it directly.
You will end up invoking your new installation using python3.10
instead.
Ubuntu is the most popular Linux distribution. So, I will assume the presence of the apt
package manager on your machine.
Should you happen to work on another distribution with a different package manager, you should find that there’s a suitable alternative with it to install what you need.
Run the following to install Python 3.10 on your machine:
user@MACHINE:~$ apt-get update
user@MACHINE:~$ apt-get install -y python3.10 python3.10-venv python3-venv
Run the following to install Python 3.10 on your machine:
user@MACHINE:~$ apt-get update
user@MACHINE:~$ apt-get install software-properties-common
user@MACHINE:~$ add-apt-repository ppa:deadsnakes/ppa
user@MACHINE:~$ apt-get update
user@MACHINE:~$ apt-get install -y python3.10 python3.10-venv python3-venv
Check installation
Once you have installed Python, type in the following to check that Python has been installed correctly.
user@MACHINE:~$ python3.10 -V
Python 3.10.6
Your operating system may have aliased python3.10
with python3
, depending on whether a Python 3 installation existed before you installed Python 3.10 or not.
So you might also be able to run python3
instead of python3.10
as a shortcut. Just make sure this is the version you want.