深度阅读

How to set python3 as default in Linux

作者
作者
2023年08月22日
更新时间
10.44 分钟
阅读时间
0
阅读量

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.

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。