If you’re using Ubuntu and want to start learning Python or need the newest version, you’re in the right place. In this post, I’ll walk you through how I installed Python 3.12 on my Ubuntu laptop. It’s not super hard, but it does take a few steps.
Before we begin, let me explain what Python is.
Python is a programming language. That means it lets you give instructions to your computer to do things like math, create websites, or even build games. Python is used by beginners and professionals because it’s easy to read and powerful at the same time.
Ubuntu is a kind of operating system, just like Windows or macOS. It’s free and open-source, and many people use it to learn programming or run servers.
Sometimes, the version of Python that comes with Ubuntu is not the newest one. As of now, Ubuntu usually comes with Python 3.10 or 3.11. But if you want the newest features, you’ll want Python 3.12.
Why Would You Want Python 3.12?
I wanted Python 3.12 because some of the tutorials I followed used it. Also, Python 3.12 runs a little faster and has small changes that make it better for writing code.
Maybe you’re also learning Python for school, a job, or just for fun. Or maybe you’re using a tool or app that only works with Python 3.12. Whatever your reason, I’ll help you get it up and running.
First, Check Your Current Python Version
Before we install anything, let’s see what version of Python you already have.
Open your Terminal. You can search for “Terminal” in the Ubuntu menu.
Type this:
python3 --version
You’ll see something like:
Python 3.10.12
If you already have 3.12, then you don’t need to keep going. But if not, keep reading.
Step 1: Install Some Required Tools
We need a few basic tools before we install Python. These tools help your computer download, build, and install software.
Open your Terminal and type:
sudo apt update
sudo apt install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
This command installs a lot of small tools. It might look scary, but it just tells Ubuntu to get everything ready.
What do these tools do?
make
,build-essential
: Help compile (build) software.libssl-dev
,zlib1g-dev
, etc.: These are libraries, kind of like ingredients in a recipe. Python needs them to work right.wget
,curl
: Used to download files.
Step 2: Download Python 3.12
Now that we have the tools, we need to get the actual Python 3.12 files.
Still in the Terminal, type:
cd /tmp
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
This downloads the Python 3.12 files and puts them in a temporary folder.
Then type:
tar -xf Python-3.12.0.tgz
cd Python-3.12.0
Now you’re inside the folder with the Python 3.12 source files.
Step 3: Build and Install Python 3.12
Next, we’ll build Python. This step tells Ubuntu to read the files and create a working version of Python 3.12.
Type:
./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall
Let’s break that down:
./configure
prepares the system.make -j$(nproc)
tells it to build using all CPU cores.sudo make altinstall
installs it without replacing your default Python version.
This step may take a few minutes. On my laptop, it took about 5–10 minutes.
Step 4: Check the New Version
Now we check if it worked.
Type:
python3.12 --version
You should see:
Python 3.12.0
If you see that, congrats! You’ve got Python 3.12 installed.
What if It Didn’t Work?
Here are some common problems I ran into:
- Missing files: Go back and double-check you typed all commands correctly.
- Old Ubuntu: If you use an old version of Ubuntu, some tools might be missing.
- No internet: Make sure your computer is online before downloading anything.
Using Python 3.12
Now that Python 3.12 is ready, you can start using it.
When you want to run Python 3.12, just use this command:
python3.12
You’ll enter the Python shell, which looks like this:
>>>
You can type simple things like:
print("Hello, world!")
To exit, press Ctrl + D
or type exit()
.
Why Not Replace the Default Python?
Ubuntu needs its default Python version to run its own apps. Changing it can break stuff. That’s why we used altinstall
. It adds Python 3.12 alongside the original.
Benefits of Python 3.12
Here are some cool things about Python 3.12:
- Faster performance: Some code runs quicker.
- Better error messages: Easier to understand when something goes wrong.
- New features: Small updates that make code simpler or safer.
Handy Tips
Here are some extra tips I picked up:
- Use
python3.12
andpip3.12
so you know you’re using the right version. - You can install packages like this:
pip3.12 install package-name
- Use a text editor like VS Code or Thonny to write your code.
Final Thoughts
Installing Python 3.12 on Ubuntu might seem like a lot at first, but once you break it into steps, it makes sense. I learned a lot by doing it myself.
If you’re just getting started with coding, don’t worry if it doesn’t go perfectly the first time. That’s how we learn.
Have you installed Python before? Did you use a different method? Let me know—I’d love to hear your experience.
Thanks for reading, and happy coding!