How to install another version of python on linux?

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

How to install another version of python on linux?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raphaelle , a month 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.