Posted on • Originally published attech.serhatteker.com on
How to Install Python 3.9 on Ubuntu
Python 3.9 released on 2020-10-04 and it offers pretty good changes likegeneric type annotations. So I want to upgrade myPython to newest version.
For all changes inPython 3.9 you can look at theChangelog :Python 3.9 Changelog
This brief tutorial shows how to install and configurePython 3.9 on Ubuntu.
There are 2 methods to install python on Ubuntu. I prefer first method and strongly recommend that but it depends on developer's taste.
Method 1: Install It From Source Code
I prefer this method since I'd rather always go to source, whether it is documentation for an API or installing something.
Out of the box default python version for Ubuntu 18.{04/10} ispython 3.6
and for Ubuntu 19.{04,10} isPython 3.7
. As now,Python 3.9.0
is the lastest stable version released as we said earlier. If you find a later version on the site, you can download it instead.
You can find all released python versions in this link:Python Versions
In order to install from source code we need to download the installer file and run the executable.
Before installing python, you must first install some required packages that are needed to build python from source. Maybe you have already installed them. However to get these packages installed, run the commands below:
$sudoapt update$sudoapt upgrade$sudoapt dist-upgrade$sudoaptinstallbuild-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Now create a temporary directory and download the python source code:
$mkdir ~/tmp$cd ~/tmp$wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
After downloading the package, run the commands below to extract the file and configure the python:
$tar-xvzf Python-3.9.0.tgz$cdPython-3.9.0$./configure
To install the python:
$sudomake altinstall
Do not use the standardmake install
as it will overwrite the system's defaultpython3 binary
—/usr/bin/python3
. Since it will probably make a mess of your OS. However it is your choice again.
Aftermake altinstall
, python should be installed and ready to use.
To test if python is installed and ready to use, run the commands below
$python3.9--version
You should see an output similar to the one below:
Python 3.9.0
For long version:
$python3.9--version--versionPython 3.9.0(default, Oct 14 2020, 19:33:53)[GCC 7.5.0]
Method 2: Installing Python via PPA
If you want to get the latest version of Python quckly installed and get future updates automatically, you can install it from the below third-party PPA repository.
First install Ubuntu software properties package if it’s not already installed on your system.
$sudoapt update$sudoaptinstallsoftware-properties-common
After that run the commands to add the PPA.
$sudoadd-apt-repository ppa:deadsnakes/ppa
Finally, run below to install Python 3.9
$sudoapt update$sudoaptinstallpython3.9
You can check as below:
$python3.9--versionPython 3.9.0# Long version$python3.9--version--versionPython 3.9.0(default, Oct 14 2020, 19:33:53)[GCC 7.5.0]
Bonus
I created a script that installsPython 3.9 as described inMethod 1.
You can check it out:install-python.
WARNING
You should always check the source code of any script before you run it.
If you want to use this script and installPython 3.9 from one-line just
run:
$wget-O - https://gist.githubusercontent.com/SerhatTeker/7d0fc99d27e9bf1d75b4435a38a89fe9/raw/install-python | bash
After the install check python as mentioned before:
$python3.9--versionPython 3.9.0# Long version$python3.9--version--versionPython 3.9.0(default, Oct 14 2020, 19:33:53)[GCC 7.5.0]
OK, All done!
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse