11

I have been using Linux servers for years now and I keep on being confused by the Filesystem Hierarchy Standard. Usually, I can live with the confusion. But now that I am developing my own software for Linux, I need to understand where it is supposed to be installed by package managers.

I was pretty convinced that /opt was the perfect location for my application. But after having investigate my Debian filesystem, I'm not sure anymore : a lot of softwares are actually installed in /usr/lib ! To name a few : MySQL, MySQLWorkbench, Nautilus, Rythmbox...

According to the FHS, /usr/lib is supposed to contain "Libraries for programming and packages" and "includes object files, libraries, and internal binaries that are not intended to be executed directly by users or shell scripts" (See here).

A lot of softwares located in /usr/lib of my debian server are not libraries or internal binaries but full-fledged user executable softwares !

I'm still on track to have my application installed in /opt. But I really would like to understand if this is correct and, above all, why.

Thanks by advance for your kind advices,

Eric.

Falcon Momot
  • 25,584

5 Answers5

12

The difference is that /usr is meant to hold packages installed as part of the system. Packages you get from the Debian/Ubuntu repositories, PPAs, etc., go here. While /opt is meant for unbundled third party applications that are not distributed through the distribution's package distribution process.

If you distribute .deb or .rpm packages, with an eye toward eventually getting your software included in the official repositories, you should install to /usr. Otherwise install to /opt. In either case, your application should be able to be compiled to run in any arbitrary location (e.g. with the help of the GNU autotools).

Michael Hampton
  • 252,907
6

The real key to understanding the Filesystem Heirarchy Standard is knowing that it is designed with network filesystems in mind.

For every machine of the same OS, release, and architecture, you can share /usr via NFS and mount it.
/usr is (re)mounted after the network stack is initialized.

/var <-- local, r/w optimized
/usr <-- can be mounted over network, possibly even read-only!
/opt <-- local, read mostly
/etc <-- local, read mostly
/srv <-- local, r/w optimized

/home <-- either/or
2

You install your libraries in <prefix>/lib , your binaries in <prefix>/bin, your header files in <prefix>/include, man pages in prefix/[share/]man, pkgconfig files in <prefix>/lib/pkgconfig or <prefix/share/pkgconfig, your cmake .m4 files in <prefix>/share/aclocal

Then let package manager decide on the prefix. If you are distributing rpm's/deb's yourself, /usr is a good choice for a prefix.

./configure --prefix=~/.local/ Should still work, so don't go hardcoding your path anywhere please!

Some libraries are wrapped into some other tool that makes them also executable and usable as a library, but they are still libraries, and not in your $PATH, so it is ok to puth them in /lib I guess.

Jens Timmerman
  • 926
  • 4
  • 12
1

I would suggest to avoid installing your app under /opt. Reason 1 : Some distros do not have /opt by default Reason 2 : /usr/lib is a standard path for libraries {If other applications need to use your library you need to add your library path manually to /etc/ldconfig} /opt is more convenient when you have standalone apps which you install manually and you want to know where they are located

One of the reason that fully fledged executables are located under /usr/lib could be that they are used from other scripts. {For example bash scripts cannot use an API directly. for this reason a common trick is to build a "wrapper" around this api and push parameters as script's arguments }

0

Please, install it in /opt.

Way too many Linux applications make the same make that Windows developers made in the 90's.

Lets install our stuff in C:\windows so that it is simple and easy to find (and slightly faster). Then came 15 years of DLL hell as different software packages needed different versions of the same libraries (which in Windows didn't have versioning of the the libraries).

Unless you are writing actual system software, put it in /opt, so that people can better track who installed what.

cmorse
  • 280
Walter
  • 1,067