Pacman 简介
简介
pacman是Manjaro的包管理工具,基本上所有的Manjaro版本都有pacman, 这个包管理工具源自上游的Arch Linux。但是Pacman也有一些Pamac不具有的功能。
重点须知
- Pacman已经被Manjaro Linux默认安装
- Pacman主要的开发和维护者是Arch Linux的开发者
- Pacman只能在命令行下使用,如果你想要用图形界面,请看下Pamac or Octopi
- Pacman是Manjaro的官方包管理工具,也有一些其他的工具。例如Arch User Repository(AUR), flatpaks 和 snaps
安装更新
安装包数据库以及更新系统上的所有包
sudo pacman -Syu
To force a full refresh of the package database and update all packages on the system. You must do this when switching branches or switching mirrors.
To force a full refresh of the package database, update all packages on the system and allow packages to be downgraded. Downgrading should be only be needed when switching to an older branch. For example, switching from Testing to Stable.
Searching for Packages
To search the Manjaro repositories for available packages you can use the command pacman -Ss keyword
. It will search both the package name and the description for the keyword. For example, to search for packages containing the keyword smplayer you could use:
You can search your installed packages in the same manner using -Qs
instead of -Ss
. To search your installed packages for smplayer:
Once you have found a package you can use pacman -Qi
to get more information about an installed packages or pacman -Si
for packages in the repos. Following the example above you could use
Finally, for a list of all installed packages on your system, enter the following command:
Installing Packages
To install a software package, the basic syntax is pacman -S packagename
. However, installing a package without updating the system will lead to a partial upgrade situation so all the examples here will use pacman -Syu packagename
which will install the package and ensure the system is up to date. For example, to install smplayer the command is:
You will then be presented a list of software to install. You may notice this list has more packages than you requested. This is because many packages also have dependencies which are packages that must be installed in order for the software you selected to function properly.
Pacman can also directly install packages from the local system or a location on the internet. The format of that command is pacman -U packagelocation
. For example, to install a copy of your package cache you could do something like:
Alternatively, you could get it directly from one of Manjaro's mirrors:
Removing Packages
To remove a software package, the basic syntax is sudo pacman -R packagename
. We could remove the smplayer package we installed above with:
This will remove the package, but will leave all the dependencies behind. If you also want to remove the unneeded dependencies you could use pacman -Rsu packagename
as seen in this example:
Sometimes when you try to remove a package you will not be able to because there are other packages which depend on it. You can use pacman -Rc packagename
to remove a package and everything that depends on it. Be careful to heed the above warning when using this option.
The most nuclear option is pacman -Rcs packagename
. This will remove everything that depends on packagename and continue to do so on its dependencies. This should really only be used in exceptional circumstances such as when removing an entire desktop environment and trying not to leave anything behind.
Pacman usually also creates backup configuration files when deleting packages. To remove those, you can add n
to any of the examples above. For example:
Viewing and Removing Orphans
To list all orphans, installed packages that are not used by anything else and should no longer be needed:
To remove all the orphans:
Downloading Packages without Installing
In some cases it may be useful to download a package without installing. For example, to install on a different system that is not connected to the internet. This can be done with pacman -Sw packagename
. For example:
The package and any rerquired dependencies will be downloaded to your pacman cache at /var/cache/pacman/pkg
Determining which Package Owns a File
It is often useful to understand which package installed a file on your system. This is easy to do with pacman using pacman -Qo /path/to/filename
. For example:
Cleaning the Cache
When pacman installs packages, it keeps a copy of all the old packages you have downloaded. This cache can be very useful if you have to install older packages in an emergency. However, left unchecked, this cache will grow very large over time. Systems running Pamac will already have access to its automated pacman cache cleaning functions. It is also possible to clean them manually using pacman.
To clear the cache of packages that are no longer installed, enter the following command:
Otherwise, to clear the cache completely, enter the following command (and use with care):
A safer way to remove old package cache files is to remove all packages except for the latest three package versions using paccache
:
The Configuration File, pacman.conf
Pacman's settings are located in /etc/pacman.conf
. This file is owned by root, please see this guide if you need more information on how to edit this file. A full reference to these options can be found in the Arch Wiki linked below. This sections features some settings that may be of particular interest to Manjaro users.
Enabling Color Output
By default, pacman's output is monochrome but enabling colored output can make the output easier to read if your terminal supports colors. This can be enabled by uncommenting or adding the following line to the file
Color
Showing PacMan Eating Power Pills
If you are bored of simply watching lines of hashes while downloading software packages in the terminal, why not change the progress bar to Pacman eating power pills instead? To enable this, simply add the line:
ILoveCandy
Troubleshooting
A separate page for pacman troubleshooting is available here.