To update Python, download the latest version of Python directly from the official Python website and run the installer. This Python installer method works on all major Operating Systems: Windows, macOS, and Linux.
Here’s a step-by-step guide that applies to all platforms:
- Visit the official Python download page:ย https://www.python.org/downloads/
- Click on the “Download Python (version)” button to download the latest version of Python for your operating system.
The website will automatically detect your OS and provide a suitable link. - Run the installer:
- On Windows, double-click the downloaded
.exe
file and follow the on-screen instructions. Make sure to check the option to add Python to your PATH environment variable. - On macOS, double-click the downloaded
.pkg
file and follow the on-screen instructions. - On Linux, the installer may be aย
.tar.xz
ย file.
Extract the file and navigate to the extracted directory in the terminal. Run the following commands:./configure
make
sudo make install
- On Windows, double-click the downloaded
- Once the installation is complete, open a new terminal or command prompt and verify the Python version using the following command:
python --version
This command will display the version of Python installed on your system.
Using the Python installer method ensures that you have the latest version of Python installed on your system, regardless of the operating system you are using. However, keep in mind that on Linux, you may need to use the command python3
instead of python
if your distribution still uses Python 2 as the default version. If you don’t prefer this method, you might want to look into other explained below.
OS Specific Methods to Update Python.
Updating Python on Windows
Using Chocolatey (Package Manager)
- If you don’t have Chocolatey installed, Install it by following the instructions on their website:ย https://chocolatey.org/install
- Open the command prompt.
- Run the following command to update Python:
choco upgrade python
- Wait for the update process to complete, then verify the Python version in a new command prompt.
Updating Python on macOS
Using Homebrew (Package Manager)
- Install Homebrew by following the instructions on their website: https://brew.sh/
- Open a terminal and run the following command to update Python:
brew update && brew upgrade python
- Wait for the update process to complete, then verify the Python version.
Updating Python on Linux
The process of updating Python on Linux varies depending on your distribution. We’ll cover the two most common package managers: apt (for Debian-based systems) and yum (for Red Hat-based systems).
Using apt (Debian-based systems)
- Open a terminal and run the following commands to update Python:
sudo apt update sudo apt install python3
- Wait for the update process to complete, then verify the Python version.
Using yum (Red Hat-based systems)
- Open a terminal and run the following command to update Python:
sudo yum update python
- Wait for the update process to complete, then verify the Python version.
Verifying Your Current Python Version
Before and after updating Python, it’s a good idea to check your current version. Doing this before updating will show you if you really need to update (your Python might already be up to date), and doing so after updating will verify if the process has been successful. You can do this by opening a terminal or command prompt and typing the following command:
python --version
This will display the version of Python installed on your system.
Why Upgrade Python?
Upgrading Python isn’t just about bragging rights (although, using the newest version is pretty cool). It’s about:
- Enhanced Security: Newer versions often patch vulnerabilities, keeping your system and projects safe from malicious attacks.
- Improved Performance: Upgrades frequently bring performance optimizations, making your code run faster and smoother.
- Exciting New Features:ย Each version introduces new functionalities and libraries, expanding your Python toolkit.