How to configure and use a newer version of Python

This article describes how to configure and use a newer Python version. You may want to do this if:

  • You have an account on a managed server, and you want to use a version of Python newer than what is installed on the server.
    This applies to all hosting accounts that have cPanel, including shared and reseller servers.
  • You have an unmanaged server, and the package repositories for your Linux distribution contain an older version of Python.

To complete the procedures in this article, you must first have a compiler and other development tools installed on your server. For information about how to do this, please see this article.

Configuring managed servers

Depending on the managed server where your account is located, there may be an older version of Python installed. If you want to run a newer version of Python, you can compile it from the source code.

Although we have tested and run this configuration, it is not supported.

To compile Python from the source code, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, type the following commands:
    cd ~
    wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
    tar xvzf Python-3.8.0.tgz
    cd Python-3.8.0
    ./configure --prefix=$HOME
    make
    make install
    
    These commands demonstrate how to install Python version 3.8.0. To install a different version, please visit https://www.python.org/ftp/python to view the versions that are available for download. After you select a version, run the previous commands with the version number you selected, instead of 3.8.0.
  3. To configure your shell environment to use the new compiled executable, type the following commands. Replace username with your own A2 Hosting account username:

    echo 'alias python3="/home/username/bin/python3.8"' >> ~/.bashrc
    source ~/.bashrc
    
  4. To confirm your account is configured to use the new version, type the following command:

    python3 --version
Installing virtualenv

If you want to create virtual environments using your new installed Python version, you must first install the virtualenv program. To do this, type the following commands:

cd ~/bin
python3.8 -m pip install virtualenv

You can then create a virtual environment by running the virtualenv program in the bin directory. For example, to create a virtual environment named testenv, type the following command:

~/bin/virtualenv testenv

To activate the new environment, type the following command:

source testenv/bin/activate

Configuring unmanaged servers

The package repositories for your Linux distribution may contain an older version of Python. If you want to run a newer version of Python, you can compile it from the source code. To do this, follow these steps:

  1. Log in to your account using SSH.
  2. As the root user, at the command prompt, type the following commands:
    cd ~
    wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
    tar xvzf Python-3.8.0.tgz
    cd Python-3.8.0
    ./configure
    make
    make install
    
    These commands demonstrate how to install Python version 3.8.0. To install a different version, please visit https://www.python.org/ftp/python to view the versions that are available for download. After you select a version, run the previous commands with the version number you selected, instead of 3.8.0.
  3. To configure the shell environment to use the new compiled executable, type the following commands. Replace executable_path with the path to the compiled Python executable (for example, /usr/local/bin):

    echo 'alias python3="/executable_path/python3.8"' >> ~/.bashrc
    source ~/.bashrc
    
  4. To confirm your account is configured to use the new version, type the following command:

    python3 --version

More Information

For more information about Python, please visit https://www.python.org.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.