Should Your Software Go in /usr/local or /opt?

Should Your Software Go in /usr/local or /opt?

As you try to install software from source or a locally built package, where do you install it? Is /usr/local the right path or does /opt make sense?

Purpose of /opt

From the FHS,

/opt is reserved for the installation of add-on application software packages.

A package to be installed in /opt must locate its static files in a
separate /opt/<package> or /opt/<provider> directory tree, where <package>
is a name that describes the software package and <provider> is the
provider's LANANA registered name.

Purpose of /usr/local

From the FHS,

The /usr/local hierarchy is for use by the system administrator when
installing software locally. It needs to be safe from being overwritten
when the system software is updated. It may be used for programs and data
that are shareable amongst a group of hosts, but not found in /usr.

Locally installed software must be placed within /usr/local rather than
/usr unless it is being installed to replace or upgrade software in /usr.

Confused Yet?

Which path do you use when you want to install, say Python, from source? What about Google Chrome? Is /opt appropriate or should you use /usr/local? Are you as confused as me?

A Simple Explanation

I found the answer to all these questions from an excellent post by Egil on Ask Ubuntu (Use of /opt and /usr/local directories in the context of a PC), and I quote,

/opt is for third-party applications that don't rely on any dependencies
outside the scope of said package. /usr/local is for packages installed on
this machine outside the scope of the distribution package manager.

An example:

An open source sip-client supplied as a .deb would install into /usr. If
it was built with the Qt framework, apt would pull it in as a dependency.

The same open source sip-client built from source would reside in
/usr/local so it would not be messed up by apt if you later installed
a .deb package for the same application. You could either build its
dependencies from source, or get them from the package manager.

A third-party application in /opt is supposed to be self-contained. For
instance, a proprietary sip-client using Qt would not rely on the version
from apt, but would have it bundled or statically linked in.

For more information, take a look at the Filesystem Hierarchy Standard.

Conclusion

I have been partial to installing Python interpreters, Rust compilers, etc. to my home directory under ~/opt. But having dabbled in FreeBSD I have realized that a lot of the Linux/BSD infrastructure assumes /usr/local is the place for local installation. Why fight the community? On my developer machine, since I have root access, I should use /usr/local for almost all software I build from source. So should you.

Plea to Debian, Ubuntu, RHEL

I'd prefer Debian, Ubuntu, RHEL, etc. to use /usr/local for all packages that are not installed on a base system. They would be following in the FreeBSD steps which make a lot of sense to me, especially since the FHS clearly states it be used for local installs by sysadmins. A package not in the base install is arguably software that an admin installs locally. Whether the admin used a package or built from source is a moot point.