有管理员账户
建议直接使用管理员账号更换你对应的用户的默认 shell:
sudo chsh -s /bin/zsh username
随后,按照后文配置 oh-my-zsh 小节的流程配置 ohmyzsh。
没有管理员账户
安装 ncurses
首先新增以下配置到 ~/.bashrc 中。
export CXXFLAGS="-fPIC"
export CFLAGS="-fPIC"
export NCURSES_HOME=$HOME/ncurses # 这里表示家目录的ncurses目录
export PATH=$NCURSES_HOME/bin:$PATH
export LD_LIBRARY_PATH=$NCURSES_HOME/lib:$LD_LIBRARY_PATH
export CPPFLAGS="-I$NCURSES_HOME/include" LDFLAGS="-L$NCURSES_HOME/lib"
保存后 使用命令 source ~/.bashrc
使其生效。
配置好环境变量后,安装 ncurses,按照下述步骤找到最新版本 ncurses 下载安装
cd ~ && mkdir ncurses && cd ncurses # 切换到根目录新建ncurses文件夹
wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz # 下载 ncurses
tar -xzvf ncurses-6.1.tar.gz # 解压
cd ncurses-6.1 # XXX需要改成最新的版本号
./configure --prefix=$HOME/ncurses --with-shared --without-debug --enable-widec
# 指定路径configure,可以自己修改想要安装的路径,这里我装到了家目录的ncurses下面了
make && make install # 安装
安装 zsh
# step 1 新建文件夹
mkdir ~/zsh && cd zsh
# step 2 下载最新版本 zsh
wget -O zsh.tar.xz https://sourceforge.net/projects/zsh/files/latest/download
# step 3 .tar.xz 文件需要解压两次
xz -d zsh.tar.xz && tar -xvf zsh.tar
# step 4 不同版本此路径不一样,cd就完事了
cd zsh-5.7.1
#step 5 指定安装路径 configure
./configure --prefix=$HOME/zsh/
# step 6 安装
make && make install
手动添加环境变量到 .bashrc 文件中并设置 zsh 为默认
export PATH=$HOME/zsh/bin:$PATH
export SHELL=$HOME/usr/bin/zsh
exec $HOME/usr/bin/zsh -l
生效 source ~/.bashrc
安装 oh-my-zsh
git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git
cd ohmyzsh/tools
REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh install.sh
下载 oh-my-zsh 插件
# zsh-syntax-highlighting
git clone https://gitee.com/Annihilater/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# zsh-autosuggestions
git clone https://gitee.com/Kagura/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
配置 .zshrc 文件
修改 ~/.zshrc 中对应内容
ZSH_THEME="clean" # 个人比较喜欢的一个极简终端主题,也可以按照你的喜好换其他的
plugins=(
z # 输入命令 z + 历史路径 快速跳转
extract # 输入命令 x + 文件名即可对各种格式的压缩包进行解压
zsh-syntax-highlighting # 代码高亮
zsh-autosuggestions # 历史代码自动补全
)
source ~/.zshrc
或重启终端即可生效。