Are you looking to find a method on how to make python3.7 default on your Linux environment? In this post, I will show you how you can make python3.7 as default on your system.
So, you have recently installed the python 3.7 version on your system and you have no idea how to set it as default.
Make python3.7 Default
The simple solution to this problem can be simple using the below code in your
.bashrc file. You need to edit the
Note that as per the above code, whenever you will use python3 it will be replaced with python3.7 and it will be set as default.
Now suppose you want to set different alias such as python2.7 and want to make that equal to the python3.7 to make it default then you can rewrite the above code as below in the
Alternate Approach to Set python3.7 as Default
The alternate approach you can take if the above solution is not working for you is that you can use the command
update-alternatives. Using this command you can easily set Python 3.7 as default in your Linux environment. The below method is most preferred.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
Note again, in the above code you use anything instead of python3. Suppose you want python3.7 to show whenever you use command python3 or anything of your liking then you can replace python3 with the word you want to use.
And as per the above code, python3.7 will always be preferred above python3.6. Now enter the below line in the terminal and press enter.
sudo update-alternatives --config python3
I strongly suggest that you use
update-alternatives rather than the
alias-approach, because aliases do not work in non-shell contexts and are therefore ineffective (also non-interactive shells ignore .bashrc).
As an illustration, consider the following python-file that begins with the shebang #!/usr/bin/env python3: If you ran myscript.py with the command./myscript.py, it would ignore your alias, however, python3 myscript.py would execute in python 3.7.1 in your situation.
Other common ambiguity-prone situations include running commands over ssh or from within a shell script, among others.
If you liked our answer then please follow us on Facebook, Twitter and Subscribe to our Newsletter to join a great community of developers around the world. Let us know the questions and answer you want to cover in this blog.