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.
Change default version of Python to 3.6
python - Permanently change the default Python3 version in Linux (Ubuntu on Windows) - Stack Overflow
How to change Python and Pip version in Ubuntu
Install python 3.11.9 on ubuntu
Videos
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.
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!
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?
Does changing the default version from python 2 to python 3 in ubuntu using the following steps have any unwanted effects?
Step 1 — Making Python 3 the Default
In this step, we will set Python 3 as the default for our python command.
First, check your current Python version.
python --version
On a fresh Ubuntu 17.10, this will output:
Python 2.7.6
We would like to have python run Python 3. So first, let's remove the old 2.7 binary.
sudo rm /usr/bin/python
Next, create a symbolic link to the Python 3 binary in its place.
sudo ln -s /usr/bin/python3 /usr/bin/python
If you run python --version again, you will now see Python 3.6.3.
or should I just stick to
alias python=python3
in /.bashrc.
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?