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:

  1. Open a terminal and type the following command: alias python=python3
  2. Press Enter. This sets the ‘python’ command to execute Python3 instead of Python2.

Method 2:

  1. Open a terminal and type the following command: sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
  2. 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:

  1. Open the .bashrc file in your home directory by running the command nano ~/.bashrc.
  2. Add the following line at the end of the file alias python=python3.
  3. Press CTRL+O to save the changes and CTRL+X to exit the editor.
  4. 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.

Tags:

related content