你能够按照如下方法使用 ls 命令来查看你的系统中都有那些 Python 的二进制文件可供使用。html
1
2
|
$
ls
/usr/bin/python
*
/usr/bin/python
/usr/bin/python2
/usr/bin/python2
.7
/usr/bin/python3
/usr/bin/python3
.4
/usr/bin/python3
.4m
/usr/bin/python3m
|
执行以下命令查看默认的 Python 版本信息:python
1
2
|
$ python --version
Python 2.7.8
|
一、基于用户修改 Python 版本:mysql
想要为某个特定用户修改 Python 版本,只须要在其 home 目录下建立一个 alias(别名) 便可。打开该用户的 ~/.bashrc文件,添加新的别名信息来修改默认使用的 Python 版本。sql
1
|
alias
python=
'/usr/bin/python3.4'
|
一旦完成以上操做,从新登陆或者从新加载 .bashrc 文件,使操做生效。bash
1
|
$ . ~/.bashrc
|
检查当前的 Python 版本。python2.7
1
2
|
$ python --version
Python 3.4.2
|
二、 在系统级修改 Python 版本ide
咱们能够使用 update-alternatives 来为整个系统更改 Python 版本。以 root 身份登陆,首先罗列出全部可用的 python 替代版本信息:post
1
2
|
# update-alternatives --list python
update-alternatives: error: no alternatives
for
python
|
若是出现以上所示的错误信息,则表示 Python 的替代版本还没有被 update-alternatives 命令识别。想解决这个问题,咱们须要更新一下替代列表,将 python2.7 和 python3.4 放入其中。学习
1
2
3
4
|
# 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.4 2
update-alternatives: using
/usr/bin/python3
.4 to provide
/usr/bin/python
(python)
in
auto mode
|
--install 选项使用了多个参数用于建立符号连接。最后一个参数指定了此选项的优先级,若是咱们没有手动来设置替代选项,那么具备最高优先级的选项就会被选中。这个例子中,咱们为 /usr/bin/python3.4 设置的优先级为2,因此update-alternatives 命令会自动将它设置为默认 Python 版本。spa
1
2
|
# python --version
Python 3.4.2
|
接下来,咱们再次列出可用的 Python 替代版本。
1
2
3
|
# update-alternatives --list python
/usr/bin/python2
.7
/usr/bin/python3
.4
|
如今开始,咱们就能够使用下方的命令随时在列出的 Python 替代版本中任意切换了。
1
|
# update-alternatives --config python
|
1
2
|
# python --version
Python 2.7.8
|
三、移除替代版本
一旦咱们的系统中再也不存在某个 Python 的替代版本时,咱们能够将其从 update-alternatives 列表中删除掉。例如,咱们能够将列表中的 python2.7 版本移除掉。
1
2
3
4
|
# update-alternatives --remove python /usr/bin/python2.7
update-alternatives: removing manually selected alternative - switching python to auto mode
update-alternatives: using
/usr/bin/python3
.4 to provide
/usr/bin/python
(python)
in
auto mode
|
方法二、移除软链接
1
2
3
|
rm
-rf
/data/logs
ln
-s
/temp/logs
/data/logs
|
解决软链接ln报错-bash: /usr/local/bin/mysql: Too many levels of symbolic links
总结
以上就是这篇文章的所有内容了,但愿本文的内容对你们的学习或者工做能带来必定的帮助,若是有疑问你们能够留言交流。
转自:https://blog.csdn.net/fang_chuan/article/details/60958329