52

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

2
42
  • 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
0
25

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').

6
  • 7
    No... 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
    Jan 15 '13 at 18:54
  • @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.
    Oct 17 '19 at 5:35
  • 2
    @Didier A., when I started using Unix ('80es) there was one machine, no networking... and they had /usr and /usr/local.
    – vonbrand
    Oct 18 '19 at 15:44
  • @vonbrand Oh I see, interesting. Then it seems the original intent of having /usr and /usr/local is still a mystery.
    – Didier A.
    Oct 19 '19 at 2:03
  • @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
    Oct 19 '19 at 13:20
8

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.

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.

1
  • 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
    Jun 20 '12 at 22:51
4

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.

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.

2
  • 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
    Mar 21 '10 at 17:31
  • 1
    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
    Oct 19 '19 at 13:23
1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy