/opt
self-contained add-on software/opt is for software that keeps to itself. Instead of spreading its files across /usr, a program installed here keeps everything in one directory of its own. It is where commercial and third-party applications usually install.
One directory per product. Delete the directory, and it is gone.
Why it exists
Every directory at the top of the tree is there for a reason. This is the problem /opt solves.
A product that brings its own libraries would clash with the system’s if it were unpacked into /usr. In /opt it cannot.
Everything the program owns is under one directory, so removing it does not mean hunting for files across the system.
What you find inside
Not everything, but the entries worth recognising. Each is marked as a directory, a file, a link or a device.
- googledirectoryGoogle Chrome, when installed from Google’s package.
- containerddirectoryFiles installed alongside Docker.
- product/bindirectoryA bundle’s own programs — not on PATH unless it is added.
- product/libdirectoryThe libraries the bundle brings with it.
At the terminal
Four commands that show what this directory is doing on a real machine.
ls /optList the add-on software installed on this machine.
du -sh /opt/*Show how much space each product takes.
ls -l /opt/google/chromeLook inside one bundle to see its own programs and libraries.
export PATH="$PATH:/opt/product/bin"Add a bundle’s programs to the directories the shell searches.
Handle with care
What goes wrong here, and what someone securing or attacking the machine looks at.
Software unpacked into /opt by hand is not known to the package manager, so system updates skip it. Keeping it patched is your job.
A program in /opt that any user can modify, but which root runs, is a route to becoming root. The files should belong to root.