Hi, folks. Ubuntu 18.04 has been with us for a while now and some of its packages are starting to get old, including Python. In this post, I will show you how to install Python 3.8 on Ubuntu 18.04
Python is one of the most popular programming languages out there. Its incredible versatility makes it be in almost any technology field. In addition, its learning curve is quite low which makes it ideal for learning.
The truth is that Ubuntu 18.04 is in its best moment of stability, but also some of its packages are starting to get old. That’s why some people update some of them individually. Especially the most important ones for work.
Therefore, if a developer wants to take advantage of the features of Python 3.8 in Ubuntu 18.04, he has to update it.
So let’s go for it.
Install Python 3.8 on Ubuntu 18.04
Ubuntu 18.04 comes with Python 3.6 by default. It’s a good version but it’s starting to get a bit outdated. However, its dependencies will help us install the new version of Python.
So, first, enable the source code repository in APT. This repository will help us to install all the dependencies of Python 3.8 in a very easy way.
To do this, open a terminal and edit the APT source file.
:~$ sudo nano /etc/apt/sources.list
And check that the next line is not already enabled:
:~$ deb-src http://archive.ubuntu.com/ubuntu/ bionic main
If it’s not in the file, add it.
Then save the changes with CTRL + O and close the file with CTRL + X.
Note: in my case, I’m using an alternative mirror to the official one.
Next, update the APT cache to recognize the added repository.
:~$ sudo apt update
And with the following command, you install all the dependencies of Python 3.6 which are the same for Python 3.8
:~$ sudo apt-get build-dep python3.6 Reading package lists... Done Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: autoconf automake autopoint autotools-dev binutils binutils-common binutils-x86-64-linux-gnu blt-dev build-essential cpp cpp-7 cpp-8 debhelper dh-autoreconf dh-strip-nondeterminism diffstat docutils-common dpkg-dev fontconfig-config fonts-dejavu-core g++ g++-7 g++-8 gcc gcc-7 gcc-7-base gcc-8 gettext intltool-debian libarchive-zip-perl libasan4 libasan5 libatomic1 libbinutils libbluetooth-dev libbluetooth3 libbz2-dev libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libcroco3 libdb-dev libdb5.3-dev libdpkg-perl libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libexpat1-dev libffi-dev libfile-stripnondeterminism-perl libfontconfig1 libfontconfig1-dev libfontenc1 libfreetype6-dev libgcc-7-dev libgcc-8-dev libgdbm-dev libgl1 libgl1-mesa-dri libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libgomp1 libice-dev libice6 libisl19 libitm1 libjs-jquery libjs-sphinxdoc libjs-underscore libllvm9 liblsan0 liblzma-dev libmpc3 libmpdec-dev libmpx2 libncursesw5-dev libpciaccess0 libpixman-1-0 libpng-dev libpthread-stubs0-dev libquadmath0 libreadline-dev libsensors4 libsm-dev libsm6 libsqlite3-dev libssl-dev libstdc++-7-dev libstdc++-8-dev libtcl8.6 libtext-unidecode-perl libtimedate-perl libtinfo-dev libtk8.6 libtool libtsan0 libubsan0 libubsan1 libx11-dev libx11-xcb1 libxau-dev libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-sync1 libxcb1-dev libxdamage1 libxdmcp-dev libxext-dev libxfixes3 libxfont2 libxft-dev libxft2 libxkbfile1 libxml-libxml-perl libxml-namespacesupport-perl libxml-sax-base-perl libxml-sax-perl libxmu6 libxpm4 libxrender-dev libxrender1 libxshmfence1 libxss-dev libxss1 libxt-dev libxt6 libxxf86vm1 linux-libc-dev m4 make pkg-config po-debconf python-babel-localedata python3-alabaster python3-babel python3-docutils python3-imagesize python3-lib2to3 python3-pygments python3-roman python3-sphinx python3-tz quilt sgml-base sharutils sphinx-common tcl tcl-dev tcl8.6 tcl8.6-dev tex-common texinfo tk tk-dev tk8.6 tk8.6-blt2.5 tk8.6-dev x11-common x11-xkb-utils x11proto-core-dev x11proto-dev x11proto-scrnsaver-dev x11proto-xext-dev xml-core xorg-sgml-doctools xserver-common xtrans-dev xvfb zlib1g-dev The following packages will be upgraded: gcc-8-base libdrm-common libdrm2 libgcc1 libsqlite3-0 libstdc++6 6 upgraded, 176 newly installed, 0 to remove and 67 not upgraded. Need to get 123 MB of archives. After this operation, 709 MB of additional disk space will be used. Do you want to continue? [Y/n]
Then, download Python 3.8.
:~$ cd /tmp :~$ sudo wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
After that, decompress the file.
:~$ tar xzvf Python-3.8.2.tgz
Now access the generated folder and start the configuration.
:~$ cd Python-3.8.2/ :~$ sudo ./configure --enable-optimizations
--enable-optimizations parameter is used to obtain an optimized Python construction. It is optional but recommended.
Now you can start the installation. But instead of using make install, we’ll use another one to avoid it replacing the version that already comes with Ubuntu. This increases the robustness and allows you to have several versions of Python.
:~$ sudo make altinstall
The installation will start at the end and you will have Python 3.8 ready for action.
If you want to verify, you can use the following command:
:~$ python3.8 -V Python 3.8.2
So, enjoy it.
Python is very popular and many developers always want to have the latest to create their applications. That’s why it is often convenient to have the latest version of Python.
Please share this post and join our Telegram channel.
More info here.