Bootcamps

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Academy

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Full-Stack Software Developer - 16w

Data Science and Machine Learning - 16 wks

Search from all Lessons


LoginGet Started

Weekly Coding Challenge

Every week, we pick a real-life project to build your portfolio and get ready for a job. All projects are built with ChatGPT as co-pilot!

Start the Challenge

Podcast: Code Sets You Free

A tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.

Listen the podcast
← Back to How to's
Edit on Github

How to update Python in Terminal?

Written by:

In order to update python version on the terminal, you can use these commands depending on your operating system:

1#Linux 2sudo apt update 3sudo apt install python3.11 4 5#MacOS 6brew install python

Here is a detailed guide about how to update python version in other operating systems. In this article, we are going to focus on how to install it on the terminal.

Update Python on Windows

To update Python on Windows you should download the Python version you want to upgrade to from python.org. In case you already have installed different Python versions and want to update the version of a virtual environment, you can do it by using the following command:

1python -m venv --upgrade VIRTUAL-ENVIRONMENT-PATH-HERE

To select which Python version we want to use, it's as simple as as writing py -version-you-want-to-use, example:

1 py -3.8 #selects Python version 3.8 2 py -3.11 # Selects Python version 3.11

Updating Python on Linux

Before getting into upgrading Python, we need to know if it's already installed (no use to upgrade something that doesn't exist). To check if Python is installed type the following:

1python3 -version

If there's an installed version of Python, the output should show you the installed version like this:

1Python 3.11.1

If your computer doesn't have Python installed, we need first to prepare our system to install Python, so we do the following:

1sudo apt update 2sudo apt install software-properties-common

Once we have downloaded the necessary files to install Python latest version, we can install it using apt-get (recommended) or using the source code.

Update with Apt-Get

There's no need to reinvent the wheel, Apt-Get it's a package manager built in Linux that will make our life easier while installing.

As a first step, let's configure the deadsnakes PPA on the system by running the following command:

1sudo add-apt-repository ppa:deadsnakes/ppa

Time to update the Apt cache and install the Python package:

1sudo apt update 2sudo apt install python3.9

Python is now updated, but still is pointing to the previously installed version. We need now to update this:

1 sudo update-alternatives --config python3

A list of options will be displayed and prompt to pick the Python version you want to point to, select it by writing the number corresponding to the version you want to use.

To verify this selection, write:

1python -version

Updating Python on MacOs

Updating Python on MacOs is more straight forward. In MacOs systems you can as well have different Python versions installed at the same time. This makes it simpler to update it by visiting python.org MacOs download page, select the installer to download and run it.

If you are more of a Homebrew user, run the following commands:

1brew install python

Once the installation finishes, you'll have the latest Python version installed which you can verify with the following code:

1python3 --version

Hope you enjoy the reading and keep on the Geek side, you can check the 4Geek's Blog for more relevant content like how to exit python in terminal.