When I install python3.9 or 3.10, there is no change in python3 command. It is still python3.8.10 and all packages will be installed for 3.8.10 unless I run a python3.9 -m pip. What is the reason that you cannot change python3 version to a newer one?
1 Answer
The reason you cannot change python3 to a newer default version is because it would break the operating system and many applications that depend on the default version of python3. You can, however, use an alias so that, when you run the python
command in the terminal, python3.9
will execute.
Open the bashrc file by using the following command:
nano ~/.bashrc
Add the following line to the below of the bashrc file .
alias python3='/usr/bin/python3.9'
After you save the file, run the following command to apply the changes:
. ~/.bashrc
-
2People may want to explain the downvotes to the author. Simply setting this as an alias is a safe alternative recommended by many other upvoted answers on other similar questions. If you have a problem running the command with
sudo
I suggest you ask a separate question or leave a comment because there is a fix for that and it has nothing to do withpython
. It's not typically recommended to installpip
packages system wide anyhow.– mchidFeb 4, 2022 at 22:38 -
If you want to install pip for python 3.9, you can use this answer. However, the OP wasn't asking that so we cannot assume they are ignorant of this.– mchidFeb 4, 2022 at 22:43
-
The default Python version used for script execution can be changed, but it cannot be changed system-wide (mentioned in previous comment) because certain components of Ubuntu depend on specific Python installations. Feb 13, 2022 at 6:12
python3
and work with the version the system comes with. If you change the default version, those Ubuntu tools may cease working, or may cease working reliably, thus protections on keeping the default version correct. You didn't say if desktop or server, but you should avoid making changes to the default python3 unless you're fully aware of those consequences.source ~/.bashrc
to apply the changes.