Linux Package Management: Day 05


๐Ÿ“ฆ What is Package Management?

Linux uses package managers to install, update, and remove software efficiently while resolving dependencies.


๐Ÿงฐ 1. Debian/Ubuntu: apt (Advanced Package Tool)

Update package list:

sudo apt update

Upgrade packages:

sudo apt upgrade

Install a package:

sudo apt install package-name

Remove a package:

sudo apt remove package-name

Remove unused packages:

sudo apt autoremove

Search for a package:

apt search nginx

๐Ÿฑ 2. RHEL/CentOS/Rocky: yum and dnf

On RHEL 8+ and Fedora, use dnf instead of yum.

Update repository cache:

sudo dnf makecache

Install a package:

sudo dnf install httpd

Remove a package:

sudo dnf remove httpd

List installed packages:

dnf list installed

Search packages:

dnf search nginx

๐Ÿ“ 3. Using rpm Directly

Install from .rpm file:

sudo rpm -ivh package.rpm

Upgrade an RPM:

sudo rpm -Uvh package.rpm

Remove an RPM:

sudo rpm -e package-name

Query installed RPMs:

rpm -qa | grep nginx

๐ŸงŠ 4. openSUSE: zypper

Install a package:

sudo zypper install vim

Remove a package:

sudo zypper remove vim

Update system:

sudo zypper update
zypper search nginx

๐Ÿ“œ 5. Package Information

Show detailed package info:

APT:

apt show curl

DNF:

dnf info curl

RPM:

rpm -qi curl

๐Ÿ—ƒ๏ธ 6. Cleaning Up

APT:

sudo apt clean
sudo apt autoremove

DNF/YUM:

sudo dnf clean all

๐Ÿ›ก๏ธ 7. GPG Keys and Repositories

Add a GPG key (APT):

wget -qO - https://example.com/key.gpg | sudo apt-key add -

Add a custom repo (YUM/DNF):

Create file in /etc/yum.repos.d/custom.repo:

[custom-repo]
name=Custom Repository
baseurl=http://example.com/repo/
enabled=1
gpgcheck=0

โœ… Summary

ToolDistrosCommand Examples
APTDebian, Ubuntuapt install, apt update, apt remove
YUMRHEL 7, CentOS 7yum install, yum update, yum remove
DNFRHEL 8+, Fedoradnf install, dnf upgrade, dnf clean
RPMAll RPM-based distrosrpm -ivh, rpm -e, rpm -qa
ZypperopenSUSEzypper install, zypper remove, update

Linux package management ensures reliable and secure software deployment.

๐Ÿ› ๏ธ How to Create a Local YUM Repository Using an ISO

This guide explains how to set up a local YUM repository from an ISO file on RHEL, CentOS, AlmaLinux, or Rocky Linux.


๐Ÿ“ฅ 1. Mount the ISO File

mkdir -p /mnt/iso
mount -o loop /dev/sr0 /mnt/iso
mkdir -p /var/www/html/yumrepo
cp -av /mnt/iso/* /var/www/html/yumrepo/
umount /mnt/iso

This step ensures the repository is persistent across reboots.


๐Ÿ“ 3. Create the Local Repo File

Create a new file /etc/yum.repos.d/local.repo with the following content:

โœ… If you copied the ISO contents:

[LocalRepo]
name=Local Repository
baseurl=file:///var/www/html/yumrepo
enabled=1
gpgcheck=0

๐Ÿ” If using the ISO directly (without copying):

[LocalRepo]
name=Local Repository
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
  • Example is given below:

VM VM

๐Ÿ”„ 4. Clean YUM and Check the Repository

yum clean all
yum repolist

You should now see LocalRepo listed in the repository list.


๐ŸŒ 5. (Optional) Serve the Repo via HTTP

This is useful if you want to share the repo with other machines.

Install Apache:

yum install -y httpd
systemctl enable --now httpd

Allow Apache Access with SELinux (if enabled):

chcon -R -t httpd_sys_content_t /var/www/html/yumrepo

Update the Repo File:

Edit /etc/yum.repos.d/local.repo to use HTTP:

[LocalRepo]
name=Local Repository
baseurl=http://localhost/yumrepo
enabled=1
gpgcheck=0

โœ… Done!

You now have a local YUM repository set up using an ISO image. You can use it offline, or serve it to multiple machines via HTTP.

๐Ÿ“Š Linux Monitoring

Monitoring Linux is critical for performance tuning, capacity planning, and troubleshooting. Below are essential CLI tools for real-time and historical system monitoring.


๐Ÿง  1. CPU and Memory Monitoring

top โ€” real-time system performance

top
  • Press M to sort by memory.
  • Press P to sort by CPU usage.

htop โ€” enhanced top (colorful UI)

htop

Install via: sudo apt install htop or sudo dnf install htop

vmstat โ€” memory, processes, and system info

vmstat 1 5
  • 1 5: sample every second for 5 times

free โ€” memory usage

free -h

๐Ÿ’ฟ 2. Disk Monitoring

df โ€” disk space usage

df -h

du โ€” directory size

du -sh /var/log

iostat โ€” CPU and I/O stats

iostat -xz 1 3

Install via: sudo apt install sysstat or sudo dnf install sysstat


๐ŸŒ 3. Network Monitoring

ip a or ifconfig โ€” IP addresses

ip a

ss โ€” socket statistics (replacement for netstat)

ss -tuln
  • -tuln: TCP/UDP listening sockets without resolving names

netstat โ€” old but useful

netstat -plntu

Might require net-tools package.

nload โ€” network bandwidth usage

nload

Install: sudo apt install nload or sudo dnf install nload


๐Ÿ“ˆ 4. System Activity Reports

sar โ€” historical performance stats

sar -u 1 3

Collects CPU usage every 1 second, 3 times.

Enable sar:

sudo systemctl enable sysstat
sudo systemctl start sysstat

๐Ÿ” 5. Process & Service Monitoring

ps โ€” process status

ps aux | grep nginx

pidstat โ€” individual process usage

pidstat -p <PID>

systemctl โ€” service status

systemctl status nginx

๐Ÿงช 6. Other Useful Tools

ToolDescriptionInstall Command
iotopShow I/O usage per processsudo apt install iotop
glancesAll-in-one monitoring dashboardsudo apt install glances
atopAdvanced top-like monitorsudo apt install atop
dstatRealtime resource monitorsudo apt install dstat

โœ… Summary Table

ResourceCommandNotes
CPUtop, htop, sarReal-time and historical usage
Memoryfree, vmstatRAM and swap
Diskdf, du, iostatDisk space and I/O
Networkss, netstat, nloadConnections & bandwidth
Processesps, pidstatProcess info and PID usage
ServicessystemctlService status

๐Ÿ” Automating Monitoring Reports

You can use cron to schedule logs and save stats:

*/5 * * * * sar -u 1 5 >> /var/log/cpu_usage.log

Linux monitoring is essential to keep your systems healthy and responsive. Regular usage of these tools helps you stay ahead of issues before they impact users.