The correct way is sudo apt install python-is-python3 - it effectively does a symlink, but it also keeps pace with future updates; so if your ubuntu distribution moves to say Python 3.9, the manual symlink will no longer work, but the package makes sure it is still valid.
The correct way is sudo apt install python-is-python3 - it effectively does a symlink, but it also keeps pace with future updates; so if your ubuntu distribution moves to say Python 3.9, the manual symlink will no longer work, but the package makes sure it is still valid.
Firstly to answer your question, your approach should work, I think the path you've given in your alias needs the / preceding the path so the command should be:
alias python='/usr/bin/python3.8'
This would indeed need to go into your ~/.bashrc file assuming you are using bash.
Secondly, Ubuntu has a really nice method of setting default binaries globally rather than messing with dot config files as depicted here: update-alternatives, so a better solution may be to simply run:
sudo update-alternatives --set python /usr/bin/python3.8
This will ensure you have the version of python in use that you intend, everywhere.
Videos
How to know the available version of Python in Ubuntu/Debian?
Which version of Python is installed by default on Ubuntu?
What is the most stable version of Python to use in Debian/Ubuntu?
From the comment:
sudo update-alternatives --config python
Will show you an error:
update-alternatives: error: no alternatives for python3
You need to update your update-alternatives , then you will be able to set your default python version.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
Then run :
sudo update-alternatives --config python
Set python3.6 as default.
Or use the following command to set python3.6 as default:
sudo update-alternatives --set python /usr/bin/python3.6
You can achieve this by applying below simple steps -
Check python version on terminal:
python --versionExecute this command to switch to python 3.6:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1Check python version:
python --versionDone.
The second line mentioned can be changed to
[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10
This gives a priority of 10 for the path of python3.
The disadvantage of alternatively editing .bashrc is that using the commands with sudo will not work.
EDIT:
I wrote this when I was young and naive, update-alternatives is the better way to do this. See @Pardhu's answer.
Outdated answer:
Open your .bashrc file
nano ~/.bashrc. Typealias python=python3on to a new line at the top of the file then save the file with ctrl+o and close the file with ctrl+x. Then, back at your command line typesource ~/.bashrc. Now your alias should be permanent.
Iโm using Ubuntu 20.04 on WT which comes with Python 3.8.5. I installed the latest versions of Python and pip however it always defaults to the one that was preinstalled. Every time I have to use Python 3.9 I need to use alias python=python3.9 first. How do I change the default to the latest versions of Python and pip so I can start using it without having to set the alias every time?
I run Ubuntu 24.04 on my laptop and it came pre installed with python 3.12.3, but I want to change it to python 3.13.7. I tried doing it following chatgpt once, but after that I couldnt open the terminal and I had to change it back to 3.12.3 via the terminal in VS Code.
Is there a safe way to change it to 3.13 or should I just stick to 3.12?
You can always use
sudo update-alternatives --config python3
and then select your python3 version.
That should solve your issue without needing to do weird configs.
I managed to solve it!
I had to do add alias python3='/usr/bin/python3.9' in my ~/.bash_aliases file (or you can add it directly in ~/.bash_rc) with no spaces, and including the number 3, to my bash script, following the video I linked above. And then I had to close and re-open the terminal - typing clear was not enough.
I'd love to hear some explanations on why the sudo update-alternatives commands didn't work though!
In almost all cases, this is a bad idea. Changing the system Python can and quite often will break some other packages depending on the previous environment or version. Upgrading from Python 3.10 to 3.13 means quite a few things have been changed and/or removed, making such problems likely.
So, how can you use a more modern version of Python?
One way ist the way you have already gone, installing it and accessing it via python3.13.
Another way is using the deadsnakes PPA, see e.g. this answer by Hannu (but refrain from overriding your system default).
And then there are multiple ways to get access to a specific Python version within a specific project, here is a small selection:
- Pyenv is the classic solution for this. It allows you to download and install basically any Python version (even alpha and beta) and activate them dynamically or use them as the base for a virtual environment.
- UV, a upcoming Python dependency manager, can manage Python versions as well. You just have to specify the desired Python version in a
.python_versionfile in your project root directory. - Conda, another dependency manager, but not limited to Python, can also manage multiple Python versions.
A simple "clean" way to install a more recent Python3 than present in Ubuntu is the deadsnakes ppa:
Howto set the default version:
https://www.debugpoint.com/install-python-3-12-ubuntu/
... at "Use Python 3.12 as the default Python3"
The basics for installation:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12
https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
The ppa gets updated, so a more recent one may well be present;
also ALWAYS verify the correctness of what is stated above.