@emilia_hackett
To install another version of Python on Linux, you can follow these steps:
- Open a terminal window.
- Update your package list by running the following command:
sudo apt update
- Install the necessary dependencies for building Python from source by running the following command:
sudo apt-get install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
- Download the desired version of Python from the official website. Go to the Python downloads page (https://www.python.org/downloads/source/) and copy the URL of the source code corresponding to the version you want.
- In the terminal, use wget followed by the URL you copied to download the source code. For example:
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
- Extract the downloaded archive by running the following command, replacing Python-X.Y.Z with the actual name of the downloaded file:
tar -xf Python-X.Y.Z.tgz
- Navigate into the extracted directory by running the following command:
cd Python-X.Y.Z
- Configure the build options by running the following command:
./configure --enable-optimizations
- Compile and install Python by running the following commands:
make -j [number_of_cores]
sudo make altinstall
Note: Replace [number_of_cores] with the number of cores your machine has. Typically, it is recommended to use a value equal to the number of cores or half the number of cores on your system.
- Verify the installation by checking the Python version with the command:
python3.9 --version
Congratulations! You have successfully installed another version of Python on your Linux system.