I want to install Python 3.9 in Ubuntu. When I run sudo apt-get python in the terminal it says that it will install Python 2 which I don't want. When I type sudo apt-get install python3.9 it shows that it is an invalid operation.
How do I install Python 3.9?
03 Answers
As you're "new to Linux", I won't suggest compiling from source. Instead, there is a PPA that you'll need to add to apt so that you can use 3.9. Here are the steps:
- Open Terminal (if it's not already open)
- Update
aptand confirm that you have the prerequisites installed:sudo apt update sudo apt install software-properties-common - The PPA you'll need to add is maintained by "deadsnakes", so let's add that:
You'll be asked if you want to continue. Press Enter to do so.sudo add-apt-repository ppa:deadsnakes/ppa - Update
aptagain:sudo apt update - Install Python 3.9:
sudo apt install python3.9 - Confirm that the installation was successful:
You should see:python3.9 --versionPython 3.9.1+
That's all there is to it. When you use anything that specifically requires Python 3.9, be sure to use python3.9 as the command, not python or python3.
Warning: Do not remove the default version of Python(3.x) which was preinstalled in Ubuntu, even if you install Python 3.9. Removing the default python version may break your system.
4Install synaptic using
sudo apt update
sudo apt-get install synapticThen, open synaptic and click on search button. Type "Python 3.9" and press Enter. Now click on the box next to python3.9 and click on mark for installation. On top click on Apply button.
You need to be running at least 20.04 with the focal-updates repository enabled. Looking at the output of the command apt-cache policy python3.9 will tell you if available when used in the Terminal program. Using apt install python3.9 if it is available can possible install it for you if the dependencies are right.