建立命令alias
安裝好debian後系統可能會自帶多個python版本,在不改變系統預設設定的前提下我們可以給當前使用者通過建alias的方式指定python版本
- 檢視當前系統已有的Python版本
dqeric@debian:~$ ll /usr/bin/python*
lrwxrwxrwx 1 root root 9 1月 24 2017 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root 9 1月 24 2017 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3779512 11月 25 2017 /usr/bin/python2.7
lrwxrwxrwx 1 root root 9 1月 20 2017 /usr/bin/python3 -> python3.5
-rwxr-xr-x 2 root root 4747120 1月 19 2017 /usr/bin/python3.5
-rwxr-xr-x 2 root root 4747120 1月 19 2017 /usr/bin/python3.5m
lrwxrwxrwx 1 root root 10 1月 20 2017 /usr/bin/python3m -> python3.5m
- 檢視預設版本
dqeric@debian:~$ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
- 檢視當前使用者配置檔案
dqeric@debian:~$ cat .bashrc
可以看到下面配置, 這個就是放alias的單獨配置檔案
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
- 新建或在已有檔案中新增配置後為
dqeric@debian:~$ cat .bash_aliases
# add alias
alias python=`/usr/bin/python3.5`
- 啟用配置後測試Python版本
dqeric@debian:~$ . ~/.bashrc
dqeric@debian:~$ python
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>