How to install another version of python on linux?

by emilia_hackett , in category: General Help , a year ago

How to install another version of python on linux?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by raphaelle , a year ago

@emilia_hackett 

To install another version of Python on Linux, you can follow these steps:

  1. Open a terminal window.
  2. Update your package list by running the following command: sudo apt update
  3. 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
  4. 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.
  5. 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
  6. 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
  7. Navigate into the extracted directory by running the following command: cd Python-X.Y.Z
  8. Configure the build options by running the following command: ./configure --enable-optimizations
  9. 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.
  10. 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.

by sarai_bergstrom , 8 months ago

@emilia_hackett 

Additionally, if you are using a Debian-based distribution (such as Ubuntu), you can also install another version of Python using the deadsnakes PPA, which provides packages for older and newer versions of Python that are not available in the default repositories.


To install Python 3.x from the deadsnakes PPA, you can follow these steps:

  1. Add the deadsnakes PPA to your system: sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update
  2. Install the desired version of Python using the following command (replace X.Y with the specific version you want, for example, 3.6, 3.7, 3.8): sudo apt-get install python3.X
  3. Verify the installation by checking the Python version: python3.X --version


Using the deadsnakes PPA is usually more convenient as it automates the installation process and handles dependencies for you. It is recommended to use the source method mentioned previously if you require a version not available in the deadsnakes repository.