zsh介绍:2: CentOS下使用zsh

在这里插入图片描述
前篇文章介绍了OSX的Catalina版本下从Bash转向zsh需要注意的事项和方法,这篇结合实例继续说明一下在CentOS下使用的zsh的方法。

事前准备

[root@liumiaocn ~]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[root@liumiaocn ~]# 

还没有安装zsh

[root@liumiaocn ~]# which zsh
/usr/bin/which: no zsh in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/root/bin)
[root@liumiaocn ~]# 

支持的shell

可以看到目前

[root@liumiaocn ~]# cat /etc/shells 
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
[root@liumiaocn ~]# echo $SHELL
/bin/bash
[root@liumiaocn ~]#

安装zsh

安装命令(OSX):homebrew install zsh

安装命令(CentOS):yum install -y zsh

安装命令(Ubuntu):apt-get install -y zsh

[root@liumiaocn ~]# yum install zsh
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: repos.lax.quadranet.com
...省略

Dependencies Resolved

========================================================================================================================================
 Package                      Arch                            Version                               Repository                     Size
========================================================================================================================================
Installing:
 zsh                          x86_64                          5.0.2-33.el7                          base                          2.4 M

Transaction Summary
========================================================================================================================================
Install  1 Package

Total download size: 2.4 M
Installed size: 5.6 M
Is this ok [y/d/N]: y
Downloading packages:
zsh-5.0.2-33.el7.x86_64.rpm                                                                                      | 2.4 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : zsh-5.0.2-33.el7.x86_64                                                                                              1/1 
  Verifying  : zsh-5.0.2-33.el7.x86_64                                                                                              1/1 

Installed:
  zsh.x86_64 0:5.0.2-33.el7                                                                                                             

Complete!
[root@liumiaocn ~]#

安装确认

[root@liumiaocn ~]# which zsh
/usr/bin/zsh
[root@liumiaocn ~]# zsh --version
zsh 5.0.2 (x86_64-redhat-linux-gnu)
[root@liumiaocn ~]# zsh --version
zsh 5.0.2 (x86_64-redhat-linux-gnu)
[root@liumiaocn ~]#

确认一下当前操作系统所支持的shell,zsh也被添加进其中了

[root@liumiaocn ~]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/bin/zsh
[root@liumiaocn ~]# 

Bash到zsh

但是重新打开终端之后,环境变量SHELL仍然没有改变

[root@liumiaocn ~]# echo $SHELL
/bin/bash
[root@liumiaocn ~]#

同样使用chsh -s /bin/zsh命令替换当前脚本即可,同样注意的是.bash_profile等Bash中如有定制的设定时需要迁移至.zshrc文件中。

[root@liumiaocn ~]# chsh -s /bin/zsh
Changing shell for root.
Shell changed.
[root@liumiaocn ~]# 

可以看到此时root用户的交互shell已经发生变化

[root@liumiaocn ~]# cat /etc/passwd |grep '^root'
root: x:0:0:root:/root:/bin/zsh
[root@liumiaocn ~]# 

但是需要注意的是,CentOS下重启机器才能生效。

[root@liumiaocn]~# echo $SHELL
/bin/zsh
[root@liumiaocn]~# 
发布了1020 篇原创文章 · 获赞 1288 · 访问量 398万+

猜你喜欢

转载自blog.csdn.net/liumiaocn/article/details/104098068
zsh
今日推荐