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

6
  • 6
    Google Chrome opts to use that directory for some reason. Jul 11, 2014 at 2:30
  • 5
    @CamiloMartin I guess it's optional.
    – a06e
    Aug 19, 2014 at 18:57
  • 6
    @becko Well, it must be an optimal choice if Google ad opted it. Aug 19, 2014 at 19:46
  • 3
    Even if you all where right, opt imus Prime sounds better.
    – m3nda
    Jan 26, 2016 at 0:42
  • 4
    Lol..I came late to the party ..But it seems like you people have opt imized the comments section a lot..:P
    – john400
    Sep 2, 2017 at 3:36

3 Answers 3

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.

6
  • 1
    so netbeans goes to /usr/local as it depends on jdk and other compilers + plus it follows linux FHS?
    – Niroshan
    Apr 14, 2011 at 4:52
  • 1
    The answer is yes.
    – Egil
    Apr 14, 2011 at 6:24
  • 1
    If i want to install conda globally as suggested here, is /opt the right place?
    – Alexey
    Mar 18, 2017 at 11:34
  • 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.
    – user13975
    Mar 31, 2018 at 2: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, 2020 at 9: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?

3
  • 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, 2011 at 17:27
  • I think other answers have said it best. Usually third-party binaries are self-contained.
    – Broam
    Apr 13, 2011 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. Jul 11, 2014 at 2: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

3
  • This answer seems to be corroborated by this Linux Journal article.
    – user13975
    Mar 31, 2018 at 2:50
  • or add symlinks from /usr/local/bin?
    – qwr
    Sep 16, 2022 at 23:58
  • You could do that, but it isn't exactly the same thing. If there is a script, and it calls another executable by just the name, then PATH works, but symlinks (of just the first script) would not.
    – TREE
    Oct 4, 2022 at 12:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .