/usr/local or /opt?

46

21

How do you generally proceed for your package installations on Linux, for packages that are not part of your distrib's repos?

On my side I am used to install in /opt. But since, I saw this doc on the Internet: http://www.pathname.com/fhs/. Now I am confused: apparently /usr/local would be also a possibility.

What is the difference between both? Any best practices to share?

Thanks

SirFabel

SirFabel

Posted 2010-03-21T17:23:42.767

Reputation:

Holy war territory and not really a programming topic to boot. – dmckee --- ex-moderator kitten – 2010-03-21T17:37:44.180

1

Similar question in Ask Ubuntu, superuser, unix&linux

– kenchew – 2016-10-07T12:41:34.670

Answers

34

  • Everything that has to be compiled & installed Unix-style and complies to FHS -> /usr/local
  • Everything else (e.g. a java web-application that comes with it's own applicationserver and loads of resources in a zip archive -> /opt

lajuette

Posted 2010-03-21T17:23:42.767

Reputation: 4 364

lintian do not allow packages to be installed on /opt neither /usr/local anymore – Cristiano – 2016-01-18T22:16:44.693

24

Just as additional interesting info: The original meaning of /usr/local is that if /usr is network-mounted (single /usr shared across multiple computers), /usr/local would be a separate filesystem local to the computer (partition on local disk).

And while on that topic, even if it's off-topic to the question: If there are multiple computers with different architectures, naturally there would be one /usr for each arch, but /usr/share would be yet another separate filesystem shared between architectures (hence 'share').

Nicolás

Posted 2010-03-21T17:23:42.767

Reputation:

@vonbrand Are you really contradicting the answer? It just sounds like whatever needs to be shared between host would be /usr, and whatever didn't need too, would be in /usr/local – Didier A. – 2019-10-17T05:35:55.573

@Didier A., when I started using Unix ('80es) there was one machine, no networking... and they had /usr and /usr/local. – vonbrand – 2019-10-18T15:44:35.733

@vonbrand Oh I see, interesting. Then it seems the original intent of having /usr and /usr/local is still a mystery. – Didier A. – 2019-10-19T02:03:09.910

@Didier A., again: /usr was what was shipped with the operating system, "standard" stuff, /usr/local was local additions (homebrewed, gotten off Usenet, filched from a friendly coleague at a convention, ...). Not standard, just common use. – vonbrand – 2019-10-19T13:20:13.040

5No... historically (yes, I was there!) /usr et al had the vendor-provided stuff, /usr/local was locally installed stuff (i.e., bash, gcc and other nice stuff). – vonbrand – 2013-01-15T18:54:46.750

7

The way I do it is that if it requires a prefix to itself OR it's a binary package, I go for /opt (which is pretty much the Solaris way). If i'm compiling from source /usr/local is how I go.

Lee

Posted 2010-03-21T17:23:42.767

Reputation: 171

6

I put everything in a private directory and then use GNU stow.

So, I'll install package X.ver to /BASE/stow/X.ver. GNU stow will then combine all the packages (with symlinks) into /BASE/bin, /BASE/lib, etc.

Conflicts and removing packages are much easier to deal with.

R Samuel Klatchko

Posted 2010-03-21T17:23:42.767

Reputation: 416

I've typically used /usr/local/stow/<packagename> as the home for stow "packages", and feel like it's a good practice - if someone else looks in /usr/local it makes it obvious what's going on and what system is maintaining the symlinks. – Stephanie – 2012-06-20T22:51:22.490

3

Here is how I do interpret the FHS standard:

/usr/local is for locally built or locally installed files, whether packaged or not that somewhat become part of that instance of the Operating System.

/opt is a place to install "foreign" packages not part of the Operating System.

As long as you only use files on the single system where you build them, /usr/local is fine, and it is therefore the default base directory for the vast majority of open source software.

If you plan to redistribute your package, I would recommend using a custom base directory like /opt/myPackage.

jlliagre

Posted 2010-03-21T17:23:42.767

Reputation: 12 469

2

Solaris used /opt a lot. Many modern Linux distros now expect packages in /usr/local/. The idea is the same - a place to put software that makes this machine do what it does, as opposed to the operating system. It's roughly analogous to "Program Files" on a Windows system.

Pick one and stick to it. It's easy enough to symlink /opt to /usr/local.

Kyle Hodgson

Posted 2010-03-21T17:23:42.767

Reputation: 162

I like Lee's comment, nice way to think about the problem. It would feel a bit weird to me to have an /opt on a Debian machine, but that's probably just personal preference. – Kyle Hodgson – 2010-03-21T17:31:47.313

Please don't. The FHS might be quite a bit dated, but it's reasoning on /usr vs/usr/local vs /opt is sound: Standard, distribution provided; locally installed, like homebrew or experimental stuff off github; vendor-provided non-standard stuff. – vonbrand – 2019-10-19T13:23:02.490

0

If you recompile a software provided by your operating system distribution, to leverage several architecture advantages specific to your very own machine, use /usr/local.

If you add a piece of software from other sources, than your operating system distribution, put it into /opt.

cp7781

Posted 2010-03-21T17:23:42.767

Reputation: 1