Search code examples
javalinuxmacosdata-storage

Where do you put global application data on Linux (Mint 13 specifically)?


I've seen people suggest /var/lib but that doesn't work on my system. Every sub-directory of /var is read-only except for /var/lock and /var/log.

Do I just need to write a Linux shell script to grant superuser access? Or is there a Java based solution?

/bin and /usr are both system file directories, so I don't want (nor can I) store files there.

As long as the application needs only to operate within the user I can use:

System.getProperty("user.home") + File.separator + ".appname"'

for the data directory.

But what about persistent system-wide data? Where does that go?

Extra Note: I have this problem with MacOS too. I can use /user/Library/Application Support for user-specific data but I have no way to access global directories.

Second Note: I am aware of and have used the Preferences API. I'm looking for a way to store data excluding that.


Solution

  • What is normally done is the application is installed using the system's packaging tools. But you could write your own installer script as well. During the installation process, run as root, a new group may be created, and a new directory under /var/lib is created owned by that group. For example, the locate command does this:

    $ ls -l /usr/bin/locate
    -rwx--s--x 1 root locate 42032 Nov 17 19:33 /usr/bin/locate
    

    And it's data dir:

    drwxr-x--- 2 root locate 4096 Nov 15  2010 /var/lib/slocate
    

    The locate command uses setgid feature to set its own process group ID to locate, that gives it permission to read the /var/lib/slocate subdirectory.

    In your case you (your installer) would set write permissions as well so the app can write data there on the users behalf.