Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)?

share|improve this question
4  
/etc is a strange and inappropriate place to leave applications... –  user5336 Dec 21 '09 at 20:31
    
I've seen people put stuff in /etc, like Perl modules. It's weird, but it happens... –  ℝaphink Dec 21 '09 at 20:55
    
For every absurdity, there is a champion to defend it. –  womble Dec 21 '09 at 21:39

3 Answers 3

up vote 56 down vote accepted

The standard for these issues is the File 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.

share|improve this answer
    
One of the few bullet lists I might like to print out as a cheat sheet ... –  stimpy77 Sep 5 '10 at 6:57
1  
+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 9 '11 at 15:58

"opt" stands for optiononal software. "var" for various system files. There for your applications should go to "/opt".

share|improve this answer
5  
/var is for varying system files, not "various". –  womble Dec 21 '09 at 19:23
2  
/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 8:35

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.

share|improve this answer
    
What would you put in /var anyway, except data? –  ℝaphink Dec 21 '09 at 20:56
    
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
    
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. –  ℝaphink Dec 22 '09 at 9:04
    
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
    
Qmail installs in /var. This is one of the numerous criticisms against it. –  staticsan May 12 '10 at 23:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.