ubuntu安装zsh

Juana_2u 记录来时的路

1、首先,查看系统里所有的shell
cat /etc/shells
2.安装zsh

1
2
3
apt install zsh #安装zsh

chsh -s /bin/zsh #将zsh设置成默认shell(不设置的话启动zsh只有直接zsh命令即可)

3、安装oh-my-zsh

事实上如果我们要是自己配置zsh的配置的话会比较麻烦,好在github上有大佬制作了一个配置文件,“oh-my-zsh”,这是目前zsh中最流行的一个配置了。(没装git :apt install git)
一般网上的一键式安装方法是(亲测没用):

1
2
wget 下载脚本并执行(网站好像是证书过期了curl -fsSL 的下载方式不行)
wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

但是不知道为什么,我在我的centos的云服务器中安装成功了,Ubuntu子系统却是报404错误,怀疑是hosts的问题,但是问题不大,我也懒得改hosts,就找了一个国内的镜像源下载了oh-my-zsh的install.sh

1
sh -c "$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)" #国内镜像源

image.png
出图,安装成功。

4、安装插件

官方推荐的插件比如:

1
2
3
4
#zsh-autosuggestions 命令行命令键入时的历史命令建议
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
#zsh-syntax-highlighting 命令行语法高亮插件
git clone https://gitee.com/Annihilater/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

5、配置文件~/.zshrc:

没什么好讲的,这是我自己的配置文件,直接复制替换原来的.zshrc即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#防止中文乱码
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
#oh-my-zsh的安装路径(zsh的配置路径)
ZSH="/root/.oh-my-zsh"
# ZSH_THEME="robbyrussell"
# 设置字体模式以及配置命令行的主题
POWERLEVEL9K_MODE='nerdfont-complete'
ZSH_THEME="agnoster" #我目前使用的模式
#ZSH_THEME="powerlevel9k/powerlevel9k"

# 启动错误命令自动更正
ENABLE_CORRECTION="true"

# 在命令执行的过程中,使用小红点进行提示
COMPLETION_WAITING_DOTS="true"

# 配置要使用的插件
plugins=(
git
extract
zsh-autosuggestions
zsh-syntax-highlighting
)
source $ZSH/oh-my-zsh.sh
source $ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
# python虚拟环境相关设置
if [ -f /usr/local/bin/virtualenvwrapper.sh ];
then
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
fi

6.我遇到了命令行提示符乱码的问题

安装结束后我发现,我的命令行出现了乱码,箭头显示不出来,如下图,这让我这个强迫症异常抓狂。
image.png
然后发现是字体的原因,这是通常设置字体的方法

1
2
3
4
5
6
7
wget https://raw.githubusercontent.com/powerline/powerline/develop/font/10-powerline-symbols.conf
wget https://raw.githubusercontent.com/powerline/powerline/develop/font/PowerlineSymbols.otf
sudo mkdir /usr/share/fonts/OTF
sudo cp 10-powerline-symbols.conf /usr/share/fonts/OTF/
sudo mv 10-powerline-symbols.conf /etc/fonts/conf.d/
sudo mv PowerlineSymbols.otf /usr/share/fonts/OTF/
fc-cache -vf /usr/share/fonts/OTF/

但是我的ubunt是window下的子系统,所以直接更改终端字体就解决了,更改方法很简单,直接下载对应的字体,直接把字体拖入在个性化里的字体设置中的添加字体即可,(百度查的很详细)
我用的是这个字体“MesloLGS NF Regular”

  • Title: ubuntu安装zsh
  • Author: Juana_2u
  • Created at : 2024-04-02 19:53:36
  • Updated at : 2024-04-02 19:55:22
  • Link: https://juana-2u.github.io/2024/04/02/ubuntu安装/
  • License: This work is licensed under CC BY-NC-SA 4.0.