A package is a compiled program plus everything it needs (its files, dependencies, config, man page) bundled into one archive that a machine can install in one step. A package manager is the tool that installs, updates, and removes those packages, and keeps track of dependencies so you don't have to.
Without a package manager, installing nginx would mean downloading source code, its dependencies, compiling everything, copying files to the right places, and remembering to do it all again for the next security patch. With a package manager, it's one command.
Linux distros split into two main package management families:
.deb packages, managed by apt (or the lower-level dpkg)..rpm packages, managed by dnf (or older yum).Commands differ, concepts don't. If you know apt, you can learn dnf in an hour. This topic covers apt because Ubuntu is what most cloud VMs default to.
apt reads a list of repositories from /etc/apt/sources.list
and files in /etc/apt/sources.list.d/. A repository is just a URL
where packages live. Every apt install downloads from one of
those URLs.
Ubuntu ships with the official Ubuntu repos already configured. Because
a package like nginx sits in those default repos, apt install pulls it
and every dependency in one command, with no manual downloads or extra
setup.