84

What is the difference between /opt and /usr/local directories and what kind of programs should be installed to them?

I referred to Linux File-system Hierarchy but the explanation is not that clear. According to above link;

/opt :- This directory is reserved for all the software and add-on packages that are not part of the default installation

/usr/local :- 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.

In the context of a PC without any networked computers what should be the directory to install a software that will be accessed by multiple local users? (i.e. where should I install a software like netbeans)

Thank you

Niroshan
  • 1,178

3 Answers3

92

/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/localso 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.

Egil
  • 14,162
  • 1
    so netbeans goes to /usr/local as it depends on jdk and other compilers + plus it follows linux FHS? – Niroshan Apr 14 '11 at 04:52
  • 1
    The answer is yes. – Egil Apr 14 '11 at 06:24
  • 1
    If i want to install conda globally as suggested here, is /opt the right place? – Alexey Mar 18 '17 at 11:34
  • @Egil, Why doesn't mac have an opt directory? – Pacerier Nov 01 '17 at 23:12
  • 1
    I previously upvoted this answer, but I now see that its conclusions differ slightly from this Linux Journal article. The article implies that with packaged software, it matters who supplied the package. If the package is from the OS's package repo, then it should be installed under /usr (or, presumably, even directly under /bin, /lib, etc) as usual. If, however, it is from another source, then it should be put into /usr/local. That would potentially include the "open source sip-client" .deb in the answer. –  Mar 31 '18 at 02:58
  • 1
    @sampablokuper The .deb file would be installed using the package management system of the OS which installs it to /usr and maintains the info of its origin as well as the way of uninstalling it. (The linked article speaks about it pretty much.) However, if the binary were distributed as a .tar.gz, for example, then you should unpack it to /usr/local. – Melebius May 25 '20 at 09:31
14

I would install third-party binary-only packages to /opt.

Anything you build yourself from source I would put in /usr/local.

netbeans is in the Ubuntu Repos. Do you need a specific version?

Broam
  • 1,161
  • Is there any rationale behind it or is it just a good practice? (I mentioned netbeans as an example - I changed that part to remove any ambiguities). Thank you – Niroshan Apr 13 '11 at 17:27
  • I think other answers have said it best. Usually third-party binaries are self-contained. – Broam Apr 13 '11 at 21:03
  • 1
    What about things that depend on runtimes, like Python or Java software? I'd put them on /opt but am not sure if it's correct. – Camilo Martin Jul 11 '14 at 02:33
11

It's all about packaging. If something is packaged in the LHS way (putting executables into bin/ libraries into lib/ etc.) it should go into /usr/local.

If something has a top level directory and doesn't follow that model, it goes in /opt. Generally, you have to explicitly add stuff in /opt to your PATH.

See also This question on superuser

TREE
  • 286