Unable to set default python version to python3 in ubuntu
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=python3
on 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.
To change Python 3.6.8 as the default in Ubuntu 18.04 to Python 3.7.
Install Python 3.7
Steps to install Python3.7 and configure it as the default interpreter.
Install the python3.7 package using apt-get
sudo apt-get install python3.7
Add Python3.6 & Python 3.7 to
update-alternatives
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
Update Python 3 to point to Python 3.7
sudo update-alternatives --config python3
Enter 2 for Python 3.7Test the version of python
python3 --version
Python 3.7.1
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.