How To Install and Switch Python Versions On Ubuntu 22.04 LinuxHostSupport
How To Install and Switch Python Versions On Ubuntu 22.04 LinuxHostSupport
In this tutorial, we are going to explain in step-by-step detail how to install multiple Python versions on Ubuntu 22.04
Python is a high-level, general-purpose programming language compatible with di�erent operating systems such as MacOS,
Windows, Linux and etc.
In this blog post, we will focus on installing Python in the Linux distributions. Also, sometimes on one Linux server, it is necessary
to be installed multiple Python versions. This tutorial will teach you about installation and changing between di�erent versions.
Installing multiple Python versions on Ubuntu 22.04 is a very easy and straightforward process that may take up to 15 minutes.
Let’s get things done!
Prerequisites
• Fresh install of Ubuntu 20.04
• User privileges: root or non-root user with sudo privileges
To check the installed version, execute the command . You should receive the following output:
root@host:~# python3.10 -V
Python 3.10.6
To check the installed version, execute the command . You should receive the following output:
root@host:~# python3.8 -V
Python 3.8.16
As you noticed, the installation process failed with the following message:
This means that Python3.6 is not in the default repository of Ubuntu 22.04. We will need to download the build from the source.
To do that, execute the following command:
cd /opt
wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
cd /Python-3.6.9
Before we proceed with installation, we need to install the prerequisites for the older Python versions:
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl
llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev libgdbm-dev libnss3-dev libedit-dev libc6-
dev
After all these preparations, we can �nally build and install it with the following commands:
./configure --enable-optimizations
To check the installed version, execute the command . You should receive the following output:
root@host:/opt/Python-3.6.9# python3.6 -V
Python 3.6.9
cd /opt
wget https://www.python.org/ftp/python/3.5.10/Python-3.5.10.tgz
cd Python-3.5.10/
./configure --enable-optimizations
To check the installed version, execute the command . You should receive the following output:
root@host:/opt/Python-3.5.10# python3.5 -V
Python 3.5.10
We need to create symbolic links for every installed Python version, including the path of the installed Python version. Execute
the following commands one by one:
To list and choose which Python version should be active, execute the following command:
You can enter any number and use that Python version. For example, we choose the Python3.10 by entering the number 1
Execute the command again, and you will notice the changed version:
root@host:/# sudo update-alternatives --config python
There are 4 choices for the alternative python (providing /usr/local/bin/python).
Congratulations! You successfully installed multiple Python versions on your system and learned how to switch them. Of course,
you do not have to do this by yourself. You can contact our technical support, and the admins will help you with any aspect of the
installation and con�guration of Python versions. We are available 24/7.
If you liked this post on how to Install and Switch Python Versions in Ubuntu 22.04, please share it with your friends on social
networks or simply leave a reply below. Thanks.
Are you facing any errors? The commands are the same, but repositories for certain versions of Python must be
added manually.
REPLY
Hi,
this is great – I searched for such a instruction quiet some time. Thank you!
It seems everything worked for me, but when I tried to install pip for python3.6 I got a segmentation fault. Do you have
any idea how I could install pip?
Thanky you,
best,
Nadine
REPLY
Is there any guide how to have di�erent pip versions ? I already installed python 3.10, 3.6 and 3.5 however the pip only
point out to python3.10.
Regards,
Iwan
REPLY
You can use the following command to install a package on a speci�c Python version: python3.6 -m pip install
“package”
Remember to change the version number on the Python command to install the package in the version you want.
REPLY
Your email address will not be published. Required �elds are marked *
Comment *
Name *
Email *
POST COMMENT
Search…
(https://www.rosehosting.com/nvme-hosting/?
mtm_campaign=blogs&mtm_source=lhs&mtm_medium=blog&mtm_content=nvme-
vps&mtm_cid=1346&mtm_group=RH&mtm_placement=sidebar)
(https://www.linuxhostsupport.com)
RECENT POSTS
CATEGORIES
Analytics (https://linuxhostsupport.com/blog/category/analytics/)
Databases (https://linuxhostsupport.com/blog/category/databases/)
Debian (https://linuxhostsupport.com/blog/category/debian/)
Guides (https://linuxhostsupport.com/blog/category/guides/)
Laravel (https://linuxhostsupport.com/blog/category/laravel/)
Linux (https://linuxhostsupport.com/blog/category/linux/)
Miscellaneous (https://linuxhostsupport.com/blog/category/miscellaneous/)
Open-source (https://linuxhostsupport.com/blog/category/open-source/)
Python (https://linuxhostsupport.com/blog/category/python/)
Security (https://linuxhostsupport.com/blog/category/security/)
Tutorials (https://linuxhostsupport.com/blog/category/tutorials/)
Ubuntu (https://linuxhostsupport.com/blog/category/ubuntu/)
Company
About Us
Contact Us
Blog
Services
Monthly Server Management
Per Incident Server Support
Support
Client Area
Follow us
Facebook (https://www.facebook.com/linuxhostsupport)
Twitter (https://twitter.com/lnxhostsupport)
LinkedIn (https://www.linkedin.com/company/linuxhostsupport.com)