12

I'm creating a project that I want to be able to distribute across platforms. I'm writing in Java and AWT which already gives me a pretty large range of devices, but I'm mostly interested in Windows and Linux (Debian/Ubuntu).

I'm trying to determine where I should put config files. I have application-wide configuration files and user-specific files. Where are common directories to put these files?

Here's my current setup:

Windows:

App Config: %PROGRAMDATA%\MyApp\config\

User Config: %USERPROFILE%\AppData\Local\MyApp\

Other:

App Config: /opt/MyApp/config

User Config: $HOME/.MyApp/

3
  • 4
    Sounds good to me. Commented Aug 8, 2012 at 23:18
  • 3
    If you're going to use environment variables to construct paths, at least use %LOCALAPPDATA%. There's nothing that guarantees that the path you constructed there from the user profile actually points out the local appdata. If you've got Win32 bindings, prefer Known Folders. Commented Aug 9, 2012 at 1:51
  • It looks like in general the problem can be avoided by using something like platformdirs Commented Mar 8, 2023 at 16:22

2 Answers 2

9

This sounds OK, it's pretty much what most software does. But in Linux, you might want to put the app configuration files in /etc (or under a subdirectory, e.g. /etc/myapp) as it's more fitting to the FHS:

/etc Host-specific system-wide configuration files

Also, you might want to put user configuration in ~/.config/MyApp rather than ~/.MyApp. This helps reduce clutter in the user's home directory.

1
  • 2
    I especially support the advice about ~/.config/MyApp rather than ~/.MyApp. Commented Mar 20, 2017 at 10:37
5

I'm no expert, but in my experience, Linux puts some default (non-editable) config files in /etc/your-app-here, whereas user-editable config files these days go in ~/.config/your-app-here (that is $HOME/.config/your-app-here)

Reference link

1
  • 1
    files under /etc/ are of course editable, and are edited to configure system-wide behaviour; however, you need special permissions (e.g. by being root) to make these changes.
    – umläute
    Commented Feb 10, 2015 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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