问题收集整理

pacman 滚动更新报错

执行 pacman -Syu 时错误信息如下:

error: lib32-alsa-lib: signature from "Felix Yan <felixonmars@gmail.com>" is invalid
:: File /var/cache/pacman/pkg/lib32-alsa-lib-1.1.0-1-x86_64.pkg.tar.xz is corrupted (invalid or corrupted package (PGP signature)).
Do you want to delete it? [Y/n]
/var/cache/pacman/pkg/libx32-flex-2.6.0-1.1-x86_64.pkg.tar.xz is corrupted (invalid or corrupted package (PGP signature)).

或者

error: custom: key "42C5AA62EF3F552D8E754F6D637B94906FC15B51" is unknown
:: Import PGP key 42C5AA62EF3F552D8E754F6D637B94906FC15B51? [Y/n] Y
error: key "42C5AA62EF3F552D8E754F6D637B94906FC15B51" could not be looked up remotely
error: failed to synchronize all databases (invalid or corrupted database (PGP signature))

反正就是类似这种说签名错误之类的,

解决方法:

最后看到了这个帖子,救命贴 :P, 得到解决办法如下:

rm -R  /etc/pacman.d/gnupg/      # 删除gnupg目录及其文件
pacman-key --init
pacman-key --populate archlinux
pacman-key --populate archlinuxcn # 启用了archlinux中文软件库的还要执行这个
pacman -Qi | awk '
/^Installed Size/ {
size = $4
unit = $5
if (unit == "KiB") {
total_size_kb += size
} else if (unit == "MiB") {
total_size_kb += size * 1024
}
}
END {
total_size_mb = total_size_kb / 1024
total_size_gb = total_size_mb / 1024
printf("Total Installed Size:\n%.2f KB\n%.2f MB\n%.2f GB\n", total_size_kb, total_size_mb, total_size_gb)
}'

pacman -Qi 命令可以查看已安装软件包的信息,其中 Installed Size 就是已安装的软件包大小。

使用 df 命令检查随 WSL2 安装的Linux发行版的 VHD 中的磁盘空间量

# 在Linux发行版中执行
wsl.exe df /

# output
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdc 1055762868 20433220 981626176 3% /

清理安装包缓存

sudo pacman -Scc

清理安装包缓存

# 不仅会删除未安装或旧版本的包文件缓存,也会将安装着的包的包文件缓存也一并删除

sudo pacman -Scc

清理孤立的软件包

# 什么是孤立的软件包呢?比如我想要吃西餐,我需要买刀叉。刀叉即西餐的一个依赖,西餐依赖于刀叉。如果我再也不想要吃西餐了,那么已经买来的刀叉也没用了。这个刀叉即孤立的软件包。既然用不上了,那么可以删掉

sudo pacman -Rns $(pacman -Qtdq)

清理日志

# 限制日志记录大小在50M
journalctl --vacuum-size=50M

安装 Arch

进入 ArchWSL 仓库下载最新 release 中的 zip 包

建议选择无 online 后缀的包

数据文件和多版本
  1. release 下载最新版的 Arch.zip
  2. 解压到 C 盘根目录,(一定要在 C 盘,其他位置也可以),但是你要有该目录的读写权限,所以不能放到 Program Files 等目录中
  3. 双击解压好的 Arch.exe 进行安装,这个 .exe 的名字 就是要创建的 WSL 实例的名字,改不同的名字就能创建多个 Arch WSL

ArchWSL 常用命令

在终端中进入 Arch.exe 所在的目录,运行 .\Arch.exe help 可查看详细命令说明;

备份

# 备份格式参数可选:tar tgz vhdx vhdxgz reg
.\Arch.exe backup --tar

恢复

.\Arch.exe install /to/file/path/backup.tar

卸载

.\Arch.exe clean

配置 Arch

经过上面的安装后,现在到 terminal 中输入 wsl 运行即可;
如果已经在使用其他的wsl系统了,那么此时直接输入wsl 并不能启动刚刚新安装的Arch,需要在终端中打开上面安装(含有 Arch.exe)时的目录,输入 .\Arch.exe 进行运行;
或者修改默认的 WSL 为刚刚安装的 Arch ,可参考:
设置默认 Linux 发行版 | WSL 的基本命令 | Microsoft Docs

创建用户

默认使用 root 用户 ,跳过

导入密钥(重要)

# 初始化密钥环 && 验证主密钥 && 更新密钥
sudo pacman-key --init
sudo pacman-key --populate archlinux
sudo pacman-key --refresh-keys

配置软件仓库

Arch Linux 软件仓库国内镜像

编辑 /etc/pacman.d/mirrorlist,里面有注释了的 China 的镜像(选择 https),选一个你喜欢的取消注释就可以了。

vim /etc/pacman.d/mirrorlist
其他跟镜像有关的可以看这里:

添加 ArchlinuxCN 源

Arch Linux 中文社区仓库 是由 Arch Linux 中文社区驱动的非官方用户仓库。包含中文用户常用软件、工具、字体 / 美化包等。

官方仓库地址:http://repo.archlinuxcn.org

echo "
[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/x86_64" >> /etc/pacman.conf

基础环境更新

# 安装archlinuxcn证书
sudo pacman -Syy archlinuxcn-keyring

# 更新软件源
# sudo pacman -Syyu --noconfirm 不提示确认对话
sudo pacman -Syyu

其它

配置下载镜像(推荐)

利用 Reflector,自动生成,生成时可设置过滤条件

sudo pacman -S reflector

安装成功后,执行下面这条命令;意思是地址为中国、最近12小时活跃、https协议、速度排序、生成镜像文件

sudo reflector --country China --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist

完成后可以输入下面的命令查看生成的镜像列表 cat /etc/pacman.d/mirrorlist

安装常用工具

pacman -S which openssh git zsh tree wget unzip

安装 AUR

pacman -S paru

zsh 配置

安装前置工具

pacman -S lua exa fzf

zsh会自动下载zinit以及zsh插件,由于速度较慢,推荐使用代理:

proxychains zsh
.zshrc 配置
# 修复emacs中不能输入中文
# LC_CTYPE="zh_CN.utf8"

# 移除重复的命令历史
setopt HIST_IGNORE_ALL_DUPS

# 取消zsh在输出不以换行符结尾的内容是在其后添加百分号并另其一行的特性
# unsetopt prompt_cr prompt_sp

# 设置可以使用通配符
setopt nonomatch

# 免输入cd进入目录
setopt auto_cd

#####################
# ZINIT #
#####################
### Added by Zinit's installer
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
print -P "%F{33} %F{34}Installation successful.%f%b" || \
print -P "%F{160} The clone has failed.%f%b"
fi

source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
### End of Zinit's installer chunk

# Load a few important annexes, without Turbo
zinit light-mode for \
zdharma-continuum/zinit-annex-as-monitor \
zdharma-continuum/zinit-annex-bin-gem-node \
zdharma-continuum/zinit-annex-patch-dl \
zdharma-continuum/zinit-annex-rust

##### autosuggestions
zinit ice wait"0a" lucid atload"_zsh_autosuggest_start"
zinit light zsh-users/zsh-autosuggestions

##### completions
zinit ice wait"0b" lucid blockf atpull'zinit creinstall -q .'
zinit light zsh-users/zsh-completions

##### syntax highlighting
zinit ice wait"0c" lucid atinit"zicompinit; zicdreplay"
zinit light zdharma-continuum/fast-syntax-highlighting

##### z.lua
zinit ice lucid wait='0d'
zinit light skywind3000/z.lua

##### fzf-tab
zinit ice wait"0f" lucid atinit"zicompinit; zicdreplay"
zinit light Aloxaf/fzf-tab
# color
zstyle ':fzf-tab:*' default-color $'\033[38;5;79m'
# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# set descriptions format to enable group support
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# preview directory's content with exa when completing
zstyle ':fzf-tab:complete:*' fzf-preview 'exa -1 --color=always $realpath'
# switch group using `,` and `.`
zstyle ':fzf-tab:*' switch-group ',' '.'

##### history search
zinit ice wait"0b" lucid atload'bindkey "$terminfo[kcuu1]" history-substring-search-up; bindkey "$terminfo[kcud1]" history-substring-search-down'
zinit light zsh-users/zsh-history-substring-search
bindkey '^A' history-substring-search-up
bindkey '^Z' history-substring-search-down

##### Load Oh MY Zsh Plugins
zinit snippet OMZ::plugins/git/git.plugin.zsh
zinit snippet OMZ::lib/history.zsh

#####################
# STARSHIP #
#####################
eval "$(starship init zsh)"

# The environment for GOLANG
export GOROOT=/usr/lib/go
export GOPATH=/home/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export GOPROXY=https://goproxy.cn,direct
export GOPRIVATE=git.ztosys.com

# The environment for RUST
export RUSTUP_DIST_SERVER=https://mirrors.sjtug.sjtu.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.sjtug.sjtu.edu.cn/rust-static/rustup

# Alias
alias l="ls -alh --color"
alias ls="ls --color"
alias ll="ls -lh --color"
alias c='clear'

source /usr/share/nvm/init-nvm.sh

插件更新

zinit update --all

zinit框架升级

zinit slef-update