Package Management and System Services

beginner linux apt yum systemctl cron

Linux has built-in package managers that handle installing, updating, and removing software. Think of them like an app store, but for the command line.

apt (Debian/Ubuntu) vs yum/dnf (RHEL/CentOS)

These are the two major package manager families. They do the same thing, just different commands.

# Debian/Ubuntu (apt)
sudo apt update                  # refresh package list (always do this first!)
sudo apt install nginx           # install a package
sudo apt remove nginx            # remove a package (keeps config files)
sudo apt purge nginx             # remove package AND config files
sudo apt upgrade                 # upgrade all installed packages
sudo apt autoremove              # clean up unused dependencies
apt search redis                 # search for a package
apt show nginx                   # show package details
# RHEL/CentOS/Fedora (yum or dnf)
sudo yum update                  # update all packages
sudo yum install nginx           # install
sudo yum remove nginx            # remove
yum search redis                 # search
yum info nginx                   # show details
# dnf is the newer replacement — same syntax as yum
sudo dnf install nginx

The key difference between apt remove and apt purge: remove keeps configuration files (so if we reinstall, our config is still there). Purge deletes everything.

Managing Services with systemctl

Once we install a service like nginx, we use systemctl to manage it.

sudo systemctl start nginx       # start now
sudo systemctl stop nginx        # stop now
sudo systemctl restart nginx     # stop + start
sudo systemctl reload nginx      # reload config (no downtime)
sudo systemctl status nginx      # check status and recent logs
sudo systemctl enable nginx      # auto-start on boot
sudo systemctl disable nginx     # don't auto-start on boot
sudo systemctl is-active nginx   # just check if running (for scripts)

A common pattern after installing something: enable it first (so it survives reboots), then start it.

sudo apt install nginx
sudo systemctl enable nginx
sudo systemctl start nginx

Reading Logs with journalctl

systemd captures all service logs. We use journalctl to read them.

journalctl -u nginx                       # all logs for nginx
journalctl -u nginx --since "30 min ago"  # recent logs
journalctl -u nginx -f                    # follow in real-time
journalctl -u nginx --no-pager -n 50      # last 50 lines, no pager
journalctl --disk-usage                   # how much space logs are using
sudo journalctl --vacuum-size=500M        # clean up logs over 500MB

Cron — Scheduling Tasks

Cron runs commands on a schedule. We edit our cron jobs with crontab -e.

The cron syntax has 5 fields:

Cron Expression Format
*
minute
0-59
*
hour
0-23
*
day
1-31
*
month
1-12
*
weekday
0-6 (Sun=0)
* = every  |  */5 = every 5  |  1,15 = specific values  |  1-5 = range

Common Cron Patterns

crontab -e    # edit cron jobs for current user
crontab -l    # list current cron jobs

# Examples:
* * * * *     /path/to/script.sh     # every minute
*/5 * * * *   /path/to/script.sh     # every 5 minutes
0 * * * *     /path/to/script.sh     # every hour (at minute 0)
0 2 * * *     /path/to/backup.sh     # daily at 2:00 AM
0 0 * * 0     /path/to/weekly.sh     # every Sunday at midnight
0 9 1 * *     /path/to/monthly.sh    # 1st of every month at 9 AM

Always redirect cron output to a log file so we can debug failures.

0 2 * * * /opt/backup.sh >> /var/log/backup.log 2>&1

The 2>&1 part redirects errors to the same log file as normal output.

Useful Tips

  • Use apt list --installed or yum list installed to see what’s installed
  • Use which nginx or command -v nginx to check if a binary is available
  • Use crontab.guru (website) to build and test cron expressions visually
  • System-wide cron jobs go in /etc/crontab or /etc/cron.d/

In simple language, package managers are how we install stuff, systemctl is how we keep it running, and cron is how we schedule it. These three tools cover most of our day-to-day Linux admin work.