How to Remove a Package and Its Dependencies with Pacman on Arch Linux

28/12/2020
Chưa phân loại

When you install packages on Arch Linux with Pacman package manager, some other packages are also installed with it. These packages are called the dependencies of the package that you tried to install. It’s all good that Pacman resolves all the dependencies and installs them for you. It saves you from manually installing them one by one, which obviously is boring and time consuming.But the problem comes in when you try to remove the package from your Arch Linux system. By default, Pacman package manager will only remove the package that you tell it to, leaving the dependencies of that package installed. The problem with that is the unnecessary packages takes extra space on the hard drive. Of course that doesn’t matter when you have a big hard drive on your local computer, but if it’s a server that you rented online, you will have limited disk space. So saving a few megabytes to a few hundreds of megabytes is still worth it.

In this article I will show you how to remove packages on Arch Linux along with their dependencies using Pacman package manager. Let’s get started.

Finding Out the Dependencies of a Certain Package

You can use pactree utility to find out the packages the package xyz depends on.

NOTE: You don’t need pactree to remove all the dependencies along with the package. But I find it interesting as it helps you understand how packages on your Arch Linux system are dependent on each other.

For example, you can check the dependency of the package filezilla with pactree as follows:

$ pactree filezilla

As you can see, pactree shows you a nicely formatted tree of dependencies of filezilla package.

You can pass -d N parameter to pactree to only print a certain depth of the tree. Here N = 1, 2, 3, …

When N=1, the direct dependency tree is printed.

You can run the following command to find out the direct dependencies of filezilla with pactree:

$ pactree -d 1 filezilla

As you can see, the direct dependencies of filezilla is listed.

You can print the list in plain format (not the tree format) with the following command:

$ pactree -d 1 -u filezilla

If you want, you can export the list to a file, let’s say filezilla.txt with the following command:

$ pactree -d 1 -u filezilla > filezilla.txt

Removing a Package and All the Dependencies with Pacman

You can remove only a specific package, let’s say filezilla using Pacman with the following command:

$ sudo pacman -R filezilla

As you can see in the screenshot below, that command would remove the package, but it would leave all the dependencies of filezilla package installed. This is what I was taking about earlier.

You can remove all the dependencies of filezilla as well with the following Pacman command:

$ sudo pacman -Rcns filezilla

As you can see in the screenshot below, all the direct dependencies are going to be removed as well. Just press y and then press <Enter> to remove all of these packages.

As you can see, all the packages are removed.

Removing Packages that Don’t Depend on Other Packages

If you didn’t know what I showed you earlier, and removed packages with sudo pacman -R command, then your Arch Linux system may have a lot of unnecessary packages still installed. But don’t regret yet. There is a way to remove these unwanted packages and save disk spaces.

You can run the following command to find out all the unnecessary packages (packages that don’t depend on other packages):

$ pacman -Qdtq

As you can see, on my Arch Linux machine, four unnecessary packages are installed.

If your Arch Linux machine show a longer list, don’t be afraid as you don’t have to remove them one by one.

You can remove all of these unnecessary packages with the following command:

$ sudo pacman -R $(pacman -Qdtq)

Press y and then press <Enter> to continue.

As you can see, all the unnecessary packages are removed.

That’s how you remove packages along with its dependencies and remove all the unnecessary packages with Pacman package manager on Arch Linux. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to create a docker image?

How to create a docker image? Docker is a tool that is designed to benefit both developers and system administrators, making...
12/02/2020

Install pngquant – Lossy PNG Compression App on Linux

If you are looking for a simple image compression tool, check out pngquant, a command-line utility and a library for lossy...
28/12/2020

Install HTop on Ubuntu

htop is a system monitoring utility that runs on the terminal. It is similar to another commonly used utility called top....
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?
27/05/2024