创建命令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.
>>> 

Eric
1 声望0 粉丝

年纪大,记性差~