99

I run a lot of open source applications including java and tomcat. It seems like most instructions have my applications running from the /var directory. But every once in a while, I also see the /opt directory. While I'm at it, I also see /usr/local/ and even /etc as well.

When should I install applications in one folder or the other? Are there pros and cons of each one? Does it have to do with the flavor history (Solaris vs Linux or Red Hat vs Ubuntu)?

gWaldo
  • 11,957
  • 8
  • 42
  • 69
Trevor Allred
  • 1,137
  • 1
  • 8
  • 7

3 Answers3

155

The standard for these issues is the Filesystem Hierarchy Standard. It's a rather big document. Basically (and very roughly), the standard paths on Linux are:

  • /bin & /sbin are for vital programs for the OS, sbin being for administrators only ;
  • /usr/bin & /usr/sbin are for not vital programs, sbin being for administrators only ;
  • /var is for living data for programs. It can be cache data, spool data, temporary data (unless it's in /tmp, which is wiped at every reboot), etc. ;
  • /usr/local is for locally installed programs. Typically, it hosts programs that follow the standards but were not packaged for the OS, but rather installed manually by the administrator (using for example ./configure && make && make install) as well as administrator scripts ;
  • /opt is for programs that are not packaged and don't follow the standards. You'd just put all the libraries there together with the program. It's often a quick & dirty solution, but it can also be used for programs that are made by yourself and for which you wish to have a specific path. You can make your own path (e.g. /opt/yourcompany) within it, and in this case you are encouraged to register it as part of the standard paths ;
  • /etc should not contain programs, but rather configurations.

If your programs are specific to the services provided by the service, /srv can also be a good location for them. For example, I prefer to use /srv/www for websites rather than /var/www to make sure the directory will only contain data I added myself, and nothing that comes from software packages.

There are some differences between distributions. For example, RedHat systems use libexec directories when Debian/Ubuntu systems don't.

The FHS is mostly used by Linux distributions (I actually don't know any other OS that really complies to it). Other Unix systems don't follow it. For example, BSD systems tend to use /usr/local for packaged programs, which is not the case for Linux. Solaris has very different standard paths.

I strongly encourage you to read the FHS document I linked above if you wish to know more about this.

raphink
  • 11,987
  • 6
  • 37
  • 48
  • 2
    One of the few bullet lists I might like to print out as a cheat sheet ... – stimpy77 Sep 05 '10 at 06:57
  • 7
    +1 for `/srv`. I was looking for a place for my git repositories and didn't like my Apache content being in `/var/www`. `/srv` seems like the perfect place. – Mr. Hedgehog Mar 09 '11 at 15:58
  • 1
    @ℝaphink, So why is it called `var` instead of `data`? – Pacerier Nov 01 '17 at 22:54
  • @Mr.Hedgehog, What do you mean by "don't like"? Care to explain? – Pacerier Nov 01 '17 at 23:01
  • 2
    @Pacerier Back in the 90's you'd be told it's `/var` because it's for "various data". In the early days Unix was hosted on a single drive. When it wasn't enough they got a new one, mounted it as `/usr` and moved all the user data there. But it wasn't enough and the old drive was full again soon. So they moved all the binaries the system could boot without from `/bin` to `/usr/bin`. They simply run out of space. Later on they needed to share data between users so they made `/var` and used it as a drop box. FHS is full of legacy decisions like that and should be taken with a pinch of salt. – cprn Nov 14 '18 at 15:07
  • Why does /usr/share have so many applications installed, but not listed here? – JustBeingHelpful Apr 14 '22 at 16:33
10

opt stands for optional software. var stands for variable system files. Therefore your applications should go to /opt.

famousgarkin
  • 349
  • 4
  • 13
Eduard Wirch
  • 352
  • 4
  • 14
  • 9
    `/var` is for *varying* system files, not "various". – womble Dec 21 '09 at 19:23
  • 5
    /var is for "variable data files". Saying it's for "various system files" is ambiguous and potentially misleading. o_O You're right about "opt" though. – phoenix8 Dec 22 '09 at 08:35
  • 2
    @Eduard, What about /opt/var then? And , ... – Pacerier Nov 01 '17 at 23:04
  • 1
    @womble It's false etymology. It's what FHS says but it's not true. Back in the 90's you'd be told it's `/var` because it's for "various data". I still have notes from a pre-internet book I read back then. – cprn Nov 14 '18 at 14:59
3

It depends on what your local standard is.

Personally, I don't install anything into /var without a good reason. My /usr/local is almost always an nfs mount off the network, so anything that isn't packaged gets installed into /opt.

David Mackintosh
  • 14,293
  • 7
  • 49
  • 78
  • 1
    What would you put in /var anyway, except data? – raphink Dec 21 '09 at 20:56
  • 1
    usually programs will stick their own stuff in /var. Mostly vendor-supplied -- logs, some libraries, control files, .pid files, that kind of thing. – David Mackintosh Dec 21 '09 at 22:03
  • 2
    I don't quite agree. Libraries, if they are static, should go in `/usr`. Dynamically-generated libs might end up in `/var/lib` occasionally, but I don't see what you would actually __install__ in `/var`, from an admin point of view. The program might use it extensively, but it should be quite empty before you launch it the program. – raphink Dec 22 '09 at 09:04
  • 1
    Right now the only thing I've deliberately installed into /var is nfsen/nfdump, and that is because the footprint of the application is all the nfdump files it accumulates. (And because this is a test install that somehow made it to production. So -- "for the ususal no good reason".)But that's pretty much it. Of course since I don't partition up my hard disk, /var, /opt and /usr are all on the same file system anyways. – David Mackintosh Dec 22 '09 at 13:56
  • 1
    Qmail installs in /var. This is one of the numerous criticisms against it. – staticsan May 12 '10 at 23:52