ubuntu20.0.4 安装zsh纪要

Z shell(Zsh)是一款可用作交互式登录的shell及脚本编写的命令解释器。Zsh对Bourne shell做出了大量改进,同时加入了Bash、ksh及tcsh的某些功能。

自2019年起,macOS的默认Shell已从Bash改为Zsh。

于是我要在我的ubuntu设备上安装zsh来增加我的愉悦值

首先下载zsh,也可以使用aptitude替代apt

$ sudo apt install zsh

查看是否安装成功了,打印版本号就ok

$ zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)

查看zsh安装位置

$ whereis zsh
zsh: /usr/bin/zsh /usr/lib/x86_64-linux-gnu/zsh /etc/zsh /usr/share/zsh /usr/share/man/man1/zsh.1.gz

网上大多数教程是使用:

sudo chsh -s /usr/bin/zsh
reboot

我自己在使用过程中发现这样做总是无效,重启或者重开中断后总是显示:

$ echo ${SHELL}
/usr/bin/bash

于是我改为下面这样就ok

sudo usermod -s /usr/bin/zsh $(whoami)
reboot

重启之后再次打开终端你将看到

This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses --- 

按键盘数字键 2,zsh 自动创建一个新的 ~/.zshrc 配置文件。
那么这个文件在哪里呢?它其实在用户家目录下面
此时的zsh缺少很多功能,你可以在~/.zshrc中添加:

alias cls='clear'
alias ll='ls -l'
alias la='ls -a'
alias vi='vim'
alias grep="grep --color=auto"

到此为止你的zsh就完全安装好了

oh-my-zsh

为了让zsh更好看,更好用,安装oh-my-zsh

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

下载好之后,使用它的.zshrc替换原本的

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

再在中添加:

alias cls='clear'
alias ll='ls -l'
alias la='ls -a'
alias vi='vim'
alias grep="grep --color=auto"

然后可以参考这篇帖子,更换喜欢的主题、设置自己的插件。主题官网在这里,可以选个自己喜欢的

上一篇:【PTA】简易连连看


下一篇:教你美化苹果电脑,终端不会用,Homebrew 没安装?