Debian 12 安装 zsh + zim + powerlevel10k

本文借鉴了 archlinux指南 的内容,我也是arch用户,这篇指南帮了我很多,就算换了别的系统也还有很多可以参考的地方。

换源与网络

如果你用的是国内的网,那么建议你换国内镜像源。同时强烈建议你打开代理,因为在安装 zim 时特别吃国际网的访问速度。

安装 zsh

更新源

# apt update

安装 zsh 相关的包

# apt install zsh zsh-autosuggestions zsh-syntax-highlighting

安装 autojump 插件

# apt install autojump

更改当前账户的默认 shell

$ chsh -s /usr/bin/zsh

进入 zsh 并配置

重启终端,会进入如下配置界面

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 ---

选择 1,进入 main menu,如下

Please pick one of the following options:

(1)  Configure settings for history, i.e. command lines remembered
     and saved by the shell.  (Recommended.)

(2)  Configure the new completion system.  (Recommended.)

(3)  Configure how keys behave when editing command lines.  (Recommended.)

(4)  Pick some of the more common shell options.  These are simple "on"
     or "off" switches controlling the shell's features.

(0)  Exit, creating a blank ~/.zshrc file.

(a)  Abort all settings and start from scratch.  Note this will overwrite
     any settings from zsh-newuser-install already in the startup file.
     It will not alter any of your other settings, however.

(q)  Quit and do nothing else.  The function will be run again next time.
--- Type one of the keys in parentheses ---

可以按你需要的设置。如果不懂,那就分别进入1、2、3的选项,进入后就0退出,就会应用默认设置。之后,选择

(0)  Exit, saving the new settings.  They will take effect immediately.

安装 zim + powerlevel10k

网络注意

请注意,在你进行这一部分之前,请确认你的国际访问流畅,否则可能出现长时等待或失败的情况。若在安装过程中失败了,请参考本文最后的【故障排除】,删除安装到一半的文件并重装

安装 curl

# apt install curl

安装 zim

$ curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh

安装成功后应该显示

All done. Enjoy your Zsh IMproved! Restart your terminal for changes to take effect.

若卡在 Installing modules... 或是其他地方长时间没响应,请按 Ctrl + c 强行停止,并参考故障排除。
若看到了类似下面的信息,可以继续正常安装,但安装好 p10k 后请参考故障排除。

! You seem to be already calling compinit in /etc/zsh/zshrc. Please remove it, because Zim's completion module will call compinit for you.
! You seem to be already calling compinit in /home/%USERNAME/.zshrc. Please remove it, because Zim's completion module will call compinit for you.

安装 powerlevel10k

编辑文件 ~/.zimrc,在文件末尾加入下面行。不会编辑文件的朋友请搜索如何使用 vim 编辑器或 nano 编辑器。

zmodule romkatv/powerlevel10k

添加完重启终端,它会自动安装 powerlevel10k 并进入配置,按你喜欢的选即可。但请注意如下的配置,请选 3 Off

                                  Instant Prompt Mode

                https://github.com/romkatv/powerlevel10k#instant-prompt

(1)  Verbose (recommended).

(2)  Quiet. Choose this if you've read and understood instant prompt documentation.

(3)  Off. Choose this if you've tried instant prompt and found it incompatible with your
     zsh configuration files.

(r)  Restart from the beginning.
(q)  Quit and do nothing.

Choice [123rq]:

使插件生效

编辑 ~/.zshrc 文件,加入如下行,重启终端,插件即生效

source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/autojump/autojump.zsh
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

故障排除

安装 zim 失败

删除 ~/ 中与 zim 有关的文件与 .zshrc 文件,因为 zim 把自己的内容也写进了 .zshrc 中,然后重启终端,再次设置 zsh。在下一次安装前,建议找个更好联网的办法。

$ rm -rf .zim .zimrc .zshrc

遇到了和 compinit 多次 calling 有关的问题

请编辑 ~/.zshrc/etc/zsh/zshrc 文件,找到和 compinit 有关的部分,把它们注释掉,如

autoload -Uz compinit
compinit
posted @ 2025-07-20 19:32  tsunchi-wong  阅读(118)  评论(0)    收藏  举报