CertNote/ Commute Study Notes
Roadmap
KOEN
CLF-C02 · FoundationalCloud Practitioner - Foundational
DVA-C02 · AssociateDeveloper - Associate
SAA-C03 · AssociateSolutions Architect - Associate
SOA-C02 · AssociateCloudOps Engineer - Associate
SAP-C02 · ProfessionalSolutions Architect - Professional
DOP-C02 · ProfessionalDevOps Engineer - Professional
Linux Master 2 · 2급KAIT Linux Master - Level 2
  • Week 1
    • 1.Operating Systems and the Kernel: What Linux Does
    • 2.The Birth of Linux: From Unix to Linus
    • 3.Free Software and Open Source: What a License Decides
    • 4.Distributions: The Unit That Bundles the Kernel and Tools for Sale
    • 5.Week 1 Review: The Identity Behind the Name Linux
  • Week 2
  • Week 3
  • Week 4
  • Week 5
  • Week 6
  • Week 7
    • 1.Package Management (1): RPM and YUM
    • 2.Package Management (2): DEB, APT, and Source Installation
    • 3.Device Files and /dev
    • 4.Using Peripherals: Printers · Sound · Scanners
    • 5.Week 7 Comprehensive Review: Packages and Devices
  • Week 8
  • Week 9
  • Week 10
  • Week 11
SCS-C03 · SpecialtySecurity - Specialty
Linux Master 1 · 1급KAIT Linux Master - Level 1
MLA-C01 · AssociateMachine Learning Engineer - Associate
AIF-C01 · FoundationalAI Practitioner - Foundational
DEA-C01 · AssociateData Engineer - Associate
MLS-C01 · SpecialtyMachine Learning - Specialty
SQLD · 개발자SQL Developer (SQLD)

© CertNote · 주간랩스

  • About
  • Changelog
  • Contact
  • Terms
  • Privacy
← Linux Master 2/Week 7/Day 2

Based on the Linux Master 2 exam syllabus·Report an error

Linux Master 2· AssociateWeek 7 · Day 2~20 min read

Day 2 - Package Management (2): DEB, APT, and Source Installation

📌 Key Takeaways

  • In the Debian family, the low-level tool is dpkg and the high-level tool is apt.
  • apt update refreshes the list, and apt upgrade does the actual upgrade. The names are confusing, but they do different jobs.
  • Source installation has four steps: extract → ./configure → make → make install.
  • tar only bundles; it does not compress. Compression is handled by the -z (gzip) · -j (bzip2) · -J (xz) options.
  • Compression ratio is generally xz > bzip2 > gzip, and speed is the reverse.

dpkg — The Low-Level Tool

dpkg -i package.deb       # install
dpkg -r package-name      # remove (keeps config files)
dpkg -P package-name      # complete removal (purge — including config)
dpkg -l                   # list of installed packages
dpkg -L package-name      # list of files the package installed
dpkg -S /path/file        # which package owns this file
OptionMeaningrpm equivalent
-iInstall-i
-rRemove (keeps config)-e
-PComplete removal—
-lList-qa
-LFile list-ql
-SFind a file's owner-qf
  • Difference between -r and -P — -r (remove) keeps config files, and -P (purge) deletes the config too.
  • dpkg also does not resolve dependencies. This is a trait common to low-level tools.
  • Just like rpm, you give a .deb file for install (-i) and a package name for removal and queries.

The First Two Letters of dpkg -l

$ dpkg -l | grep -E 'apache2-bin|vsftpd'
ii  apache2-bin    2.4.52-1ubuntu4    amd64    Apache HTTP Server (modules and other binary files)
rc  vsftpd         3.0.5-0ubuntu1     amd64    lightweight, efficient FTP server written for security
MarkerMeaning
iiProperly installed state
rcRemoved but config files remain (removed, config-files)
No lineNever installed, or completely removed with -P
  • rc is exactly where the difference between -r and -P becomes visible. After dpkg -r vsftpd it remains as rc, and after dpkg -P vsftpd it disappears from the list.
  • The reason for keeping config is so the old settings can be reused as they were when you reinstall. To start fresh and clean, purge.

Package File Names — How They Differ from RPM

   apache2 _ 2.4.52-1ubuntu4 _ amd64 . deb
      │            │             │
      │            │             └── architecture
      │            └──────────────── version-revision
      └───────────────────────────── package name
ItemRPMDEB
SeparatorHyphens and dots (name-version-release.architecture)Underscores (name_version_architecture)
64-bit Intel/AMDx86_64amd64
Architecture-independentnoarchall
  • Even for the same program, the package name can differ by distribution. The Apache web server is httpd in the Red Hat family and apache2 in the Debian family. The httpd in the apt examples below matches the name to yesterday's for easy comparison; on a real Ubuntu you install it with apt install apache2.

When dpkg Is Blocked by Dependencies

MethodCommand
Clean up an install that stopped, using aptapt install -f (--fix-broken) — fetches the missing dependency packages and finishes the job
Install the file with apt from the startapt install ./package.deb — put ./ in front to signal that it is a file

apt — The High-Level Tool

apt update                 # refresh package list (does not install!)
apt upgrade                # upgrade installed packages
apt install httpd          # install
apt remove httpd           # remove
apt purge httpd            # remove including config
apt search keyword         # search
apt show httpd             # info
apt list --installed       # installed list

⚠️ Always distinguish update from upgrade. apt update only fetches a fresh list of "which versions of which packages exist" from the repository. It does not actually install or change anything. apt upgrade looks at that list and actually upgrades. So you always use the order apt update && apt upgrade.

CommandWhat it does
apt updateRefreshes the list only
apt upgradeActual upgrade
apt-getThe older apt command. It still works
aptitudeA management tool with a text screen
  • Repository addresses are in /etc/apt/sources.list and /etc/apt/sources.list.d/.
  • It is the same place as /etc/yum.repos.d/ in the RPM family.

Why apt update Exists Separately

   Repository server                    My computer
   package list  ── apt update ───────►  copy of the list (/var/lib/apt/lists/)
   package files ── apt upgrade ──────►  actual install · update
                    apt install
  • apt works from the copy of the list stored on my computer. If the copy is stale, it does not know new versions have come out, and it fails trying to fetch old files that have already vanished from the repository.
  • That is why you run apt update first even before installing. If apt install on a freshly installed Ubuntu says "package not found", you usually have never fetched the list.
  • yum has no separate step for this. If the list is stale, yum fetches a fresh one on its own when it runs, and yum update goes straight to the actual upgrade. The same word update does different things in the two families.
CommandRefreshes listChanges packages
apt updateYesNo
apt upgradeNoYes
yum check-updateAutomatically if neededNo
yum updateAutomatically if neededYes

The Remaining apt Commands

CommandWhat it does
apt full-upgrade (apt-get dist-upgrade)Upgrades, and if necessary even allows removing existing packages
apt autoremoveCleans up packages that came along as dependencies and are now useless
apt cleanEmpties the downloaded .deb cache (/var/cache/apt/archives)
apt-cache search keywordSearch — the older form of apt search
apt-cache show package-nameInfo — the older form of apt show
  • In the past the commands were split: apt-get for installing, apt-cache for searching. apt gathers the frequently used features into one command.
  • The difference between apt remove and apt purge is exactly the same as between dpkg -r and -P — whether config files are kept or deleted.

Reading One sources.list Line

   deb  http://archive.ubuntu.com/ubuntu  jammy  main restricted
    │                 │                     │         │
    │                 │                     │         └── components (areas)
    │                 │                     └──────────── codename of the distribution release
    │                 └────────────────────────────────── repository address
    └──────────────────────────────────────────────────── deb = binary, deb-src = source
  • After editing a line, you must run apt update for the new repository's list to come in.
  • Recent distributions sometimes put the same content in a file of a different format (.sources under /etc/apt/sources.list.d/). The location the exam asks about is /etc/apt/sources.list.

Correspondence Table for the Two Families

TaskRPM familyDEB family
Low-level installrpm -idpkg -i
Low-level removalrpm -edpkg -r
Low-level listrpm -qadpkg -l
High-level installyum installapt install
High-level removalyum removeapt remove
Repository settings/etc/yum.repos.d//etc/apt/sources.list

Compression and Bundling

Bundling (archive) and compressing (compress) are different jobs.

CommandWhat it doesExtension
tarBundle multiple files into one.tar
gzip / gunzipCompress / decompress.gz
bzip2 / bunzip2Compress / decompress.bz2
xz / unxzCompress / decompress.xz
compressOld method.Z
   ratio   xz  >  bzip2  >  gzip
   speed   gzip  >  bzip2  >  xz
  • tar itself does not compress. It only bundles. That is why names that go through two steps, like .tar.gz, are common.

Compression Tools Handle Only One File

$ ls
access.log  error.log
$ gzip access.log
$ ls
access.log.gz  error.log
$ gunzip access.log.gz
$ ls
access.log  error.log
  • gzip deletes the original and replaces it with a .gz. The original and the compressed file do not remain together. The same goes for bzip2 and xz.
  • All three tools compress one file at a time and cannot make multiple files into one lump. That is why to compress a whole directory you must bundle it with tar first.
Taskgzipbzip2xz
Compressgzip filebzip2 filexz file
Decompressgunzip · gzip -dbunzip2 · bzip2 -dunxz · xz -d
View contents without unpackingzcatbzcatxzcat
tar option-z-j-J
Common bundle extension.tar.gz · .tgz.tar.bz2.tar.xz
  • Decompression works with -d (decompress) for all three. gunzip does the same job as gzip -d.
  • zip and unzip are a different family. They do bundling and compression in one go and are used when exchanging files with Windows (.zip).

tar Options

tar -cvf bundle.tar folder/        # bundle (create)
tar -xvf bundle.tar                # extract (extract)
tar -tvf bundle.tar                # list contents only (list)
tar -zcvf bundle.tar.gz folder/    # bundle and gzip-compress
tar -zxvf bundle.tar.gz            # gzip-decompress and extract
tar -jxvf bundle.tar.bz2           # bzip2
tar -Jxvf bundle.tar.xz            # xz
OptionMeaning
-cBundle (create)
-xExtract (extract)
-tList only the contents (list)
-fSpecify the file name — almost always needed
-vShow progress (verbose)
-zgzip
-jbzip2
-Jxz (uppercase)

Mixing up -c (bundle) and -x (extract) can overwrite the original. The pairing -z is lowercase gzip, -j is bzip2, -J is uppercase xz also shows up as is.

The Order for Reading Option Letters

   tar  -z c v f  backup.tar.gz  /home/alice
         │ │ │ │        │             │
         │ │ │ │        │             └── what to bundle
         │ │ │ │        └──────────────── file name that -f takes
         │ │ │ └── f : what follows is the archive file name
         │ │ └──── v : show the files being processed on screen
         │ └────── c : action (exactly one of c · x · t)
         └──────── z : compression method (one of z · j · J)
  • You pick exactly one of c, x, t as the action. To that you attach one compression method plus v and f.
  • Put f last. The thing right after f is interpreted as the file name. Writing tar -cfv a.tar dir tries to create an archive named v.
  • Writing without the hyphen, as tar zxvf file, means the same thing. Both notations appear in the choices.
OptionMeaning
-C directorySpecifies where to extract (uppercase). Without it, extracts into the current directory
-pExtracts while preserving the original permissions
-rAppends files to an existing archive (cannot be used on compressed archives)
tar -zxvf backup.tar.gz -C /tmp        # extract under /tmp
tar -ztvf backup.tar.gz                # only see what is inside, without extracting
  • Recent GNU tar can sometimes detect the compression format on its own when extracting. But when bundling, nothing is compressed unless you give an option, and on the exam you pick as the answer the one with the option matching the extension.
  • The habit of looking at the list first with -t is safe. Extracting an archive bundled without a top-level directory dumps hundreds of files into the current directory.

Installing from Source

When there is no package or you need to choose the options yourself, you compile the source.

   1  tar -zxvf program-1.0.tar.gz     extract
   2  cd program-1.0
   3  ./configure                      check environment · generate Makefile
   4  make                             compile
   5  make install                     install (usually with root privileges)
StepWhat it does
./configureChecks the system and creates the Makefile
makeReads the Makefile and compiles
make installCopies the built results into place
make cleanCleans up intermediate compile files
  • You can specify the install location as in ./configure --prefix=/opt/myapp.
  • With source installation, you must also take care of dependencies yourself, and removal is hard. Using packages whenever possible is recommended.
  • If you do not give --prefix, it usually installs under /usr/local. That location keeps it from mixing with /usr, where packages install.
  • The ./ before configure means "the one in the current directory". The current directory is not in PATH, so typing just configure will not find it. make, on the other hand, is a command installed on the system, so no ./ is attached.

Where Each Step Gets Stuck

Message on screenWhich stepCause
configure: error: no acceptable C compiler found in $PATH./configureNo compiler (gcc)
configure: error: … not found./configureA needed library or header is missing — you must fill in the dependency yourself
make: *** No targets specified and no makefile found. Stop.make./configure was skipped, so there is no Makefile
Permission deniedmake installWriting to system directories needs root privileges
  • The three steps form a chain in which each step takes the output of the previous one. make reads the Makefile that ./configure made, and make install copies the executable that make built. That is why the order cannot be changed.
  • By convention, ./configure and make are run as a regular user, and only make install as root.
ItemPackage installSource install
Time takenShort — already compiledLong — compiled on my computer
DependenciesResolved automatically by the high-level toolResolved by hand
RemovalOne line: rpm -e · apt removeHard — there is no database tracking the installed files
Visible in lists?Shows in rpm -qa · dpkg -lDoes not show
Reason to chooseMost casesWhen there is no package, or you need the latest version or specific compile options

Tomorrow we cover device files and the /dev directory.

📖 Glossary

  • dpkg: The low-level package tool of the Debian family. It does not resolve dependencies.
  • apt: The high-level tool of the Debian family. It uses repositories and handles dependencies too.
  • apt update: The command that only fetches a fresh package list from the repository.
  • apt upgrade: The command that actually updates packages to their latest versions.
  • tar: A command that bundles multiple files into one. It has no compression of its own.
  • gzip / bzip2 / xz: Compression tools. Their extensions are .gz, .bz2, and .xz respectively.
  • ./configure: The step in source installation that checks the system and generates the Makefile.
  • make install: The step that installs the compiled results onto the system.

📝 Practice Questions

Click a choice to reveal the answer and explanation.

Question 1

Which of the following is the low-level management tool that handles .deb packages?

Question 2

Which of the following is what the apt update command does?

Question 3

Which of the following is the correct order when compiling and installing source code?

Question 4

Which of the following is the option used to bundle files with the tar command?

Question 5

Which of the following is the option to specify with the tar command when also using bzip2 compression?

PreviousPackage Management (1): RPM and YUMWeek 7 · Day 1Next Device Files and /devWeek 7 · Day 3

Official references

  • Linux Master 2 official exam syllabus(opens in a new tab)

On this page

  • Key Takeaways
  • dpkg — The Low-Level Tool
  • The First Two Letters of `dpkg -l`
  • Package File Names — How They Differ from RPM
  • When dpkg Is Blocked by Dependencies
  • apt — The High-Level Tool
  • Why `apt update` Exists Separately
  • The Remaining apt Commands
  • Reading One sources.list Line
  • Correspondence Table for the Two Families
  • Compression and Bundling
  • Compression Tools Handle Only One File
  • tar Options
  • The Order for Reading Option Letters
  • Installing from Source
  • Where Each Step Gets Stuck
  • Glossary
  • Practice Questions