zoukankan      html  css  js  c++  java
  • update-alternatives将Linux下python默认版本切换成替代版本

    1. 查看当前系统有哪些版本

    $ ls /usr/bin/python*

    2、基于用户修改 Python 版本

    想要为某个特定用户修改 Python 版本,只需要在其 home 目录下创建一个 alias(别名) 即可。打开该用户的 ~/.bashrc 文件,添加新的别名信息来修改默认使用的 Python 版本。

    alias python='/usr/bin/python3.5'

    一旦完成以上操作,重新登录或者重新加载 .bashrc 文件,使操作生效。

    $ . ~/.bashrc

    检查当前的 Python 版本。

    $ python --version

    Python 3.5

    3、 在系统级修改 Python 版本

    使用 update-alternatives 来为整个系统更改 Python 版本。以 root 身份登录,首先罗列出所有可用的 python 替代版本信息:

    # update-alternatives --list python

    update-alternatives: error: no alternatives for python

    如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。想解决这个问题,我们需要更新一下替代列表,将 python2.7 和 python3.5放入其中。

    # update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

    update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode

    # update-alternatives --install /usr/bin/python python /usr/bin/python3.5

    update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python (python) in auto mode

    --install 选项使用了多个参数用于创建符号链接。最后一个参数指定了此选项的优先级,如果我们没有手动来设置替代选项,那么具有最高优先级的选项就会被选中。

    使用下方的命令随时在列出的 Python 替代版本中任意切换了。

    # update-alternatives --config python

    4、移除替代版本

    一旦我们的系统中不再存在某个 Python 的替代版本时,我们可以将其从 update-alternatives 列表中删除掉.如移除python2.7

    # update-alternatives --remove python /usr/bin/python2.7

  • 相关阅读:
    MySql触发器简介
    MySQL存储过程
    MySQL自定义函数
    MySql视图
    MySQL增删改
    MySQL内联和外联查询
    MySql运算符
    SQL scripts
    Adding Swagger to Web API project
    Unable to get setting value Parameter name: profileName
  • 原文地址:https://www.cnblogs.com/fengtai/p/12865147.html
Copyright © 2011-2022 走看看