Packages: what apt install actually does
apt is Ubuntu's package manager. apt install fetches an archive, unpacks its files into known places and keeps a receipt, so apt remove can undo it.
Sooner or later something tells you to run apt install, and a wall of text scrolls past. It is not magic and it is not a download button. It is a program that fetches archives, unpacks files into known places, and writes down what it did. Run it as the wrong user and it will tell you so.
Five paths, no magic. The binary is a file you can ls -l, the docs are files, and that last symlink is the one that matters for the next block: it is how the package told systemd to start nginx when the machine boots. On this box, 668 packages had already done exactly this before you logged in.
What you just learned
A package is an archive plus a list of where its files go. apt works out what else that archive needs, fetches everything, and hands it to dpkg, which unpacks the files into /usr/sbin, /etc, /usr/share and friends. Then it writes down every path it touched.
That last part is the whole point. Because the receipt exists, apt remove knows exactly what to delete, dpkg -L can tell you what a package owns, and which nginx can point at a plain file sitting in a plain directory. Nothing was installed "into the system". Files were copied to places, the same way block 01 said.
It needs root because those directories belong to root: the same permission check from block 03, different error message. And when it says the lock is held, that is usually Ubuntu installing security updates in the background. Wait a minute and try again.
Seen on a real server
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?- apt was run as a normal user. Put sudo in front. If you are root and still see a lock, Ubuntu is installing updates in the background: wait a minute.
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.- The package telling systemd to start nginx at boot. A symlink is a file that points at another file.
apt gave nginx a service file for free, which is why it starts at boot. Your own app has none. Next: writing one.