2019-03-26 21:39:48 +08:00
|
|
|
|
# Pacman
|
|
|
|
|
|
2020-04-27 11:36:57 +08:00
|
|
|
|
Pacman 是 ArchLinux 及其分版的软件包管理工具,本文简单介绍其使用方法和常见问题处理。
|
|
|
|
|
|
2020-12-10 10:29:08 +08:00
|
|
|
|
## 1.Search
|
2019-03-26 21:39:48 +08:00
|
|
|
|
|
2020-04-27 11:36:57 +08:00
|
|
|
|
使用如下命令查找软件包:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2019-08-02 15:26:37 +08:00
|
|
|
|
pacman -Ss <key words>
|
|
|
|
|
```
|
2019-03-26 21:39:48 +08:00
|
|
|
|
|
2020-12-10 10:29:08 +08:00
|
|
|
|
## 2.Install
|
2019-03-26 21:39:48 +08:00
|
|
|
|
|
2020-04-27 11:36:57 +08:00
|
|
|
|
使用如下命令安装软件包:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2022-04-29 13:20:16 +08:00
|
|
|
|
sudo pacman -S <package name>
|
2019-08-02 15:26:37 +08:00
|
|
|
|
# if error <file> exists in filesystem
|
2022-04-29 13:20:16 +08:00
|
|
|
|
sudo pacman -S <package name> --force
|
2019-08-02 15:26:37 +08:00
|
|
|
|
```
|
2019-03-26 21:39:48 +08:00
|
|
|
|
|
2021-01-20 14:52:20 +08:00
|
|
|
|
## 3.Query
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pacman -Qs <key words>
|
|
|
|
|
# list installed packages only found in sync db(s) [filter]
|
|
|
|
|
pacman -Qen
|
|
|
|
|
# list installed packages not found in sync db(s) [filter]
|
|
|
|
|
pacman -Qem
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.Remove
|
2019-03-26 21:39:48 +08:00
|
|
|
|
|
2020-04-27 11:36:57 +08:00
|
|
|
|
卸载命令和常用参数如下:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
|
|
|
|
$ pacman -Rscun <package name>
|
2019-08-02 15:26:37 +08:00
|
|
|
|
-c, --cascade remove packages and all packages that depend on them
|
|
|
|
|
-n, --nosave remove configuration files
|
|
|
|
|
-s, --recursive remove unnecessary dependencies
|
|
|
|
|
-u, --unneeded remove unneeded packages
|
|
|
|
|
```
|
2019-08-02 15:27:19 +08:00
|
|
|
|
|
2021-01-20 14:52:20 +08:00
|
|
|
|
## 5.Refresh Package Databases
|
2020-12-10 10:29:08 +08:00
|
|
|
|
|
|
|
|
|
长时间不进行更新的话本地 package databases 会与远程的不一致,导致安装软件时出现:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
error: failed retrieving file
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
这样的错误,此时需要使用以下命令更新 package databases
|
|
|
|
|
|
|
|
|
|
```bash
|
2022-04-29 13:20:16 +08:00
|
|
|
|
sudo pacman -Syu
|
2020-12-10 10:29:08 +08:00
|
|
|
|
```
|
|
|
|
|
|
2021-01-20 14:52:20 +08:00
|
|
|
|
## 6.Update
|
2019-08-02 15:27:19 +08:00
|
|
|
|
|
2020-04-27 11:36:57 +08:00
|
|
|
|
使用如下命令升级软件包和系统。
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2022-04-29 13:20:16 +08:00
|
|
|
|
sudo pacman -Syu
|
2021-06-27 14:30:15 +08:00
|
|
|
|
# 或
|
2022-04-29 13:20:16 +08:00
|
|
|
|
sudo pamac update
|
2022-05-17 23:13:37 +08:00
|
|
|
|
# -uu:enables downgrades
|
|
|
|
|
# -yy:to force a refresh even if up to date
|
|
|
|
|
sudo pacman -Syyuu
|
2019-08-02 15:27:19 +08:00
|
|
|
|
```
|
2020-04-27 11:36:57 +08:00
|
|
|
|
|
2021-01-20 14:52:20 +08:00
|
|
|
|
## 7.从本地文件安装
|
2020-07-14 10:45:37 +08:00
|
|
|
|
|
2020-09-24 00:18:47 +08:00
|
|
|
|
使用如下命令可以从本地“\*.pkg.tar.xz”(2020年1月份以后改为 “\*.pkg.tar.zst”)文件进行安装:
|
2020-07-14 10:45:37 +08:00
|
|
|
|
|
|
|
|
|
```bash
|
2022-04-29 13:20:16 +08:00
|
|
|
|
sudo pacman {-U --upgrade} [选项] <文件>
|
2020-07-14 10:45:37 +08:00
|
|
|
|
```
|
|
|
|
|
|
2021-01-20 14:52:20 +08:00
|
|
|
|
## 8.问题处理
|
2020-04-27 11:36:57 +08:00
|
|
|
|
|
2021-01-20 14:52:20 +08:00
|
|
|
|
### 8.1.conflicting files
|
2020-04-27 13:47:16 +08:00
|
|
|
|
|
2020-04-27 11:36:57 +08:00
|
|
|
|
在升级或安装软件包时经常遇到如下错误:
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2020-04-27 11:36:57 +08:00
|
|
|
|
error: failed to commit transaction (conflicting files)
|
|
|
|
|
xxxxxxxxx exists in filesystem
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
此时可以使用 --overwrite 强制覆盖该文件。
|
|
|
|
|
|
2020-05-20 16:18:39 +08:00
|
|
|
|
```bash
|
2022-04-29 13:20:16 +08:00
|
|
|
|
sudo pacman -Syyu --overwrite '*'
|
2020-04-27 11:36:57 +08:00
|
|
|
|
```
|