You can use the ls command as follows to check which Python binary files are available in your system.
1 2 |
|
Execute the following command to view the default Python version information:
1 2 |
|
1. Modify the Python version based on the user:
If you want to modify the Python version for a specific user, just create an alias in his home directory. Open the user's ~/.bashrc file and add new alias information to modify the default Python version.
1 |
|
Once the above operation is completed, log in again or reload the .bashrc file for the operation to take effect.
1 |
|
Check the current Python version.
1 2 |
|
2. Modify the Python version at the system level
We can use update-alternatives to change the Python version for the entire system. Log in as root and first list all available python alternative version information:
1 2 |
|
If the error message shown above appears, it means that the alternative version of Python has not been updated-alternatives Command recognition. To solve this problem, we need to update the substitution list to include python2.7 and python3.4.
1 2 3 4 |
|
The --install option takes multiple parameters for creating symbolic links. The last parameter specifies the priority of this option. If we do not set an alternative option manually, the option with the highest priority will be selected. In this example, we set priority 2 for /usr/bin/python3.4, so the update-alternatives command will automatically set it as the default Python version.
1 2 |
|
Next, we again list the available alternative versions of Python.
1 2 3 |
|
Now, we can use the command below to switch between the listed alternative versions of Python at any time.
1 |
|
1 2 |
|
3. Remove alternative versions
Once an alternative version of Python no longer exists in our system, we can remove it from the update-alternatives list Delete it. For example, we can remove the python2.7 version from the list.
1 2 3 4 |
|
Method 2, remove the soft link
1 2 3 |
|