How Do I Upgrade my Python on Debian

In order for you to perform this operation to update your Python version, you need to update your CentOS 8 and have root rights for your VPS

Checking Your Python Version

In order to go to upgrade your python, you need to check its version. This can be done using the following command:

python3 -V

If python is successfully installed on your server, then you should get something like this:

Python 3.6.7

Updating your Python Version

First, you need to install the required dependencies to compile the Python source code. This can be done using a special command, which is presented below:

# apt-get install wget build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev liblzma-dev -y

After that, we recommend going to the Python source download page to find the latest gzip version of the source code. Replace the urls and filenames in this tutorial with the latest version. Then download your python

wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz

After that, you need to unpack the archive that you just downloaded. You can do it like this:

tar xzf Python-3.9.6.tgz

Next, compile the Python source

cd Python-3.9.6 && ./configure --enable-optimizations

This is followed by the installation of your Python. Use the following command:

make altinstall

After that, a mandatory step for execution will be to check the name of your new Python executable file

ls /usr/local/bin/python*

Then Install the new default Python executable. Replace the two instances of /python3.9 in the following command with the name of your new Python executable

update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1

Update your PIP

An important step for this update is to update your pip.

/usr/local/bin/python3.9 -m pip install --upgrade pip

Then you should check the name of your new pip executable

ls /usr/local/bin/pip*

Set the new item as default. Use the name of your new pip executable in the following command:

update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.9 1

After that, you need to check the current version of your installed Python. You can make sure like this:

python -V && pip -V

After that, you will be able to see the following:

Python-3.9.6
pip 21.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

Was this article helpful?

Related Articles

Leave A Comment?