How to set python3 as default in Linux
Published on Aug. 22, 2023, 12:16 p.m.
To set Python3 as the default version in Linux, you can use one of several methods. Here are some steps you might follow:
Method 1:
- Open a terminal and type the following command:
alias python=python3
- Press Enter. This sets the ‘python’ command to execute Python3 instead of Python2.
Method 2:
- Open a terminal and type the following command:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
- Press Enter. This sets up the update-alternatives system, which allows the system to have multiple versions of a program installed and select the appropriate version automatically.
Method 3:
- Open the .bashrc file in your home directory by running the command
nano ~/.bashrc
. - Add the following line at the end of the file
alias python=python3
. - Press
CTRL+O
to save the changes andCTRL+X
to exit the editor. - Run the following command in your terminal to update your Bash shell
source ~/.bashrc
.
These are some common methods to set Python3 as the default version in Linux.