How To Upgrade Python Version From Cloud Shell Aws

Upgrading the Python version from Cloud Shell in AWS is a useful skill to have, especially as Python continues to evolve with new features and improvements. In this article, I will guide you through the process of upgrading Python in AWS Cloud Shell, sharing personal insights and tips along the way.

Checking Current Python Version

Before we begin the upgrade, let’s first check the current version of Python installed in the AWS Cloud Shell. To do this, simply open the Cloud Shell and input the following command:

python --version

This will display the currently installed Python version. It’s important to know the existing version before proceeding with the upgrade.

Upgrading Python with pyenv

One of the most reliable methods to upgrade Python on AWS Cloud Shell is by using pyenv. Pyenv is a fantastic tool for managing multiple Python versions on a single machine.

First, we need to install pyenv. Use the following commands to install pyenv:

curl https://pyenv.run | bash

After the installation, add pyenv to your shell environment by executing the following command:

echo 'export PATH="/home/ec2-user/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec $SHELL

Now that pyenv is set up, we can proceed to install the desired Python version:

pyenv install 3.9.6

Replace ‘3.9.6’ with the version you wish to install or upgrade to. After installation is complete, set it as the global version:

pyenv global 3.9.6

Updating PATH

It is crucial to update the PATH to ensure the system recognizes the new Python version. Execute the following command to refresh the PATH:

export PATH="/home/ec2-user/.pyenv/versions/3.9.6/bin:$PATH"

Verifying the Upgrade

To confirm that the Python version has been successfully upgraded, enter the following:

python --version

If the displayed version matches the one you installed, congratulations! You have successfully upgraded Python in the AWS Cloud Shell.

Conclusion

Upgrading Python version in AWS Cloud Shell using pyenv is a valuable skill. By following these steps, you can ensure that you are always working with the latest version of Python and have access to its newest features and improvements. Happy coding!