# Configuring and using a newer version of Python

> Download, compile and use a newer Python version in your account when the server's default version is too old.

Source: https://helpcenter.ruachost.com/developers/programming-languages/configuring-and-using-a-newer-version-of-python/

This guide explains how to download, compile, and configure a newer Python version on your hosting account. This is useful if the server’s default Python version is older than what your application requires.

## When to use a newer Python version

- Managed servers (shared hosting) where the installed Python version is older than required.
- Unmanaged servers where package repositories contain older Python versions.

> **Note:**
This applies to all cPanel hosting accounts.

## Requirements

- You must have a compiler and development tools installed on your server.

## Configuring a newer Python version on managed servers

1. Log in to your account using SSH.
2. Download and extract the Python source code:

```
cd ~
wget https://www.python.org/ftp/python/3.12.8/Python-3.12.8.tgz
tar xvzf Python-3.12.8.tgz
cd Python-3.12.8
```

3. Compile and install Python to your home directory:

```
./configure --prefix=$HOME
make
make install
```

4. Configure your shell to use the new Python version (replace `username` with your account username):

```
echo 'alias python3="/home/username/bin/python3.12"' > ~/.bashrc
source ~/.bashrc
```

5. Verify the new Python version:

```
python3 --version
```

## Using Python virtual environments

Python 3 includes built-in support for virtual environments using the `venv` module.

- To create a virtual environment:

```
python3 -m venv testenv
```

- To activate it:

```
cd testenv && source bin/activate
```

## Configuring a newer Python version on unmanaged servers

If the system repositories have an older Python version, you can compile it from source:

1. Log in to your server via SSH as root.
2. Download and extract the source code:

```
cd ~
wget https://www.python.org/ftp/python/3.12.8/Python-3.12.8.tgz
tar xvzf Python-3.12.8.tgz
cd Python-3.12.8
```

3. Compile and install:

```
./configure
make
make install
```

4. Configure your shell to use the new executable (replace `executable_path` with the path to the compiled Python executable, e.g., `/usr/local/bin`):

```
echo 'alias python3="/executable_path/python3.12"' > ~/.bashrc
source ~/.bashrc
```

5. Confirm the Python version:

```
python3 --version
```

## More Information

For further details about Python versions, downloads, and documentation, visit [Python.org](https://www.python.org/).
