Package Managers in Linux (To Be Continued)
This post tries to simply introduce some package managers and their basic usage.
pacman
The pacman package manager is the default package manager of Arch Linux. Learn more about pacman on the official wiki here.
pacman - Changing to mirror
Before you start to use pacman, changing its source to mirror source in your country might be greatly helpful.
Firstly, find a mirror you need on Mirror Overview of ArchLinux offical site. Here I choose the mirror from my mother school, whose URL is https://mirrors.njupt.edu.cn/archlinux/
.
Then, edit /etc/pacman.d/mirrorlist
, and paste the string below into the file.
1 | Server = https://mirrors.njupt.edu.cn/archlinux/$repo/os/$arch |
Last, save the file and run sudo pacman -Syu
to update.
The file
/etc/pacman.d/mirrorlist
has already provided many mirrors in it. So you can just skip the first step above, just edit the mirrorlist file. Find the server you want, and delete the#
at the begining of that line to uncomment it.
For an easy copy, here are some mirrors in China:
1 | ### China |
pacman - Upgrading packages
Run the command below to upgrade packages.
1 | sudo pacman -Syu |
You are recommended to immediately run this command after changing to a mirror.
pacman - Querying package(s)
To find the package you need in the sync database:
1 | pacman -Ss <package_name> |
The "s" in the small case means "search".
To list the packages installed:
1 | pacman -Qq // list all the packages, ignore version (-q) |
pacman - Installing package(s)
This command helps install one or more packages.
1 | sudo pacman -S <package_name1> <package_name2> ... |
For example, to install bat, run:
1 | sudo pacman -S bat |
pacman - Removing package(s)
This command helps remove a single package, leaving all of its dependencies installed:
1 | sudo pacman -R <package_name> |
To remove a package and its dependencies that are not required by any other installed package:
1 | sudo pacman -Rs <package_name> |
Here I found a helpful article that provides more information: 《Arch Linux 软件包的查询及清理》.
APT
The APT(Advanced Packaging Tools) is(Maybe "are"? Since it's "tools"?) widely used in Debian and Ubuntu etc. It mainly includes apt-get
,apt-cache
and apt-file
.
APT - Changing to mirror
Take Tsinghua's mirror as an example:
1 | ## Tsinghua |
APT - Useful commands
1 | sudo apt update // update the package info |