25 January 20
I use GNU/Linux. It’s pretty good. One of the things I really like
about NIX based operating systems is the ability for you to manage all
your packages from the command line. I can attest that this is the best
way to manage your packages. There are many package managers out there
for all the various distributions of Linux. I happen to use Arch Linux,
a rather minimal version of linux. Almost all of the packages you need,
need to be installed by the user. Arch based systems use the
pacman
package manager. So how do use it effectively? My
honest opinion is to run the following command in your terminal:
man pacman
Honestly, just read it. But if you can’t make head or tail out of the man page, here are some of the commands that you should know how to use. First, the command to install packages:
pacman -S [package_name]
Now, if you want to search for a package in the official Arch package repositories, this is the command used to query the database:
pacman -Ss [query]
So, that covers the basics of installing packages. Now for maintenance. This is the command used to upgrade all installed packages:
pacman -Syu [query]
You will use that command the most. Now this command is useful, but rarely used:
pacman -Rns $(pacman -Qtdq)
That one requires a bit of explanation. Basically, this one line does
two things. First, it generates a list of all the unused packages and
their orphans with pacman -Qtdq
. It passes the list to
pacman -Rns
which then removes them as well as the
configuration files generated by it. If you have always uninstalled
packages cleanly, this command should return a No arguments
passed error. If however, you have done some messy uninstalls, this
one-liner gets rid of the stuff you don’t use and won’t need.
Now for removing packages. This should be the only command that you use:
pacman -Rns
It removes the package, the dependencies that were installed for it that are not dependencies for other packages, and all the configuration files that were produced. It basically reverts you to the state your machine was in during pre-install.
This is something that always infuriated me about Windows. When you tried to uninstall something, the program may have gone, but if you happen to browse the program files later on, you would find the remains of them lodged somewhere.No clean uninstalls. Linux package managers do a much better job of this.
Now what if you want some specific information regarding packages that you have already installed? There are ways to get what you want. Say you want to list all the packages installed on your system. Simply run the following command:
pacman -Q
This will literally list out all the packages that are installed on your system. If you want to know how many you have in total, run the following command:
pacman -Q | wc -l
Which should give you the right number. But this shows everything.
All the dependencies. Packages that were a part of the base
group and the base-devel
group. So more useful command to
that can be used to see the packages that you have explicitly installed
is the following:
pacman -Qte
And you can pipe that into wc -l
again to get the
number.
Now say you want to find where a certain package has installed its
files. This happens sometimes. I used it recently when I wanted to
install zsh-autosuggestions
and could not find the file
that I wanted to source from my .zshrc
. Run the following
command:
pacman -Ql [package_name]
If you run the above command without specifying a package, Pacman will list out all the package files of all the packages installed on your system. Its a long list.
And that should cover the basics.
Best regards,