To set Python 3 as the default Python version in Ubuntu, you can use the update-alternatives
command. Here are the steps:
Update Alternatives
Use the update-alternatives
command to set Python 3 as the default:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
Configure Alternatives
Next, configure the default Python version:
sudo update-alternatives --config python
You will see a list of installed Python versions. Select the number corresponding to Python 3.
Verify the Change
Finally, verify that Python 3 is now the default:
python --version
Example:
Here’s a complete example of the commands:
sudo apt update
sudo apt install python3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
sudo update-alternatives --config python
python --version