Where and How to store program information in Linux
I'm new to Linux and I've only ever messed around with it but now I want to allow my Java program to run on Linux...
I've had a quick look around on the internet, and I've found a list of directories and their discriptions. /usr/lib
seems to be the best place for me to store program information, but I've just looked in there on my VirtualBox VM and it appears that I can't write there, even with root permissions. So if anyone can point me in the right direction that would be brilliant.
I have also noticed that Linux h开发者_JAVA技巧as it's own "Software Center", and I'm afraid that I may be going to wrong way about all this, so may be some sort of introduction to programming on Linux would help if anybody would be kind enough to provide one!
Thanks In Advance
PS My Virtual Machine is an Ubuntu distribution
The file system structure of not only Linux, but any POSIX-compatible system (including BSD, Solaris, and to a lesser degree even Mac OS X) are standardized in the FHS. Specifically for Ubuntu, have a look at the Debian policy for Java and the packaging guide of the ubuntu-java team.
If your program is run interactively, it should store information(like databases and settings) in $HOME/.your-program-name
(or $HOME/.config/your-program-name
). If your program is a system service, it should store its information in /var/lib
. You can also install a default configuration into /etc/your-program-name
.
The binaries are a whole different deal, and a prefix to their location should be configurable. To get the full advantage of the Software Center and its dependency/update mechanisms, package your software. These binaries(and the libraries that go with them) will go into to /usr/
tree if packaged, and /usr/local/
if manually installed. No matter the prefix, binaries go into bin
(i.e. /usr/bin
), libraries into lib32
/lib64
, and other data into share
.
If you don't want to package your program and don't want to follow the structure imposed by FHS (but you really should do that), the alternative is putting code and other objects into /opt/your-program-name
. Note that the (mutable) data your program generates and operates on should still go into $HOME/.your-program-name
(interactive) or /var/lib/your-program-name
(service).
Store it under the home directory of the user, who is running the program - in a hidden directory (preceded with dot), for example: .program-data. The short path to it would be: ~/.program-data and a full path to it depends on the distro of the OS - usually /home/[user name]/.program-data
The simplest place to store an application is in a home directory. You may want to create a user and separate home directory for a service.
However it sounds like you are writing a command line or GUI tool in Java. A common place to store applications is under a bin
directory like /usr/local/bin
or /home/myuser/bin
lib
is usually for shared libraries loaded by applications. (Java doesn't use them)
You should always store/install applications & programs in $HOME directory.
This will allow you to easily find the applications & programs.
Make separate folders for Softwares & Programs under $HOME for easily identification.
Also, add JAVA_HOME environment variable in .bashrc file.
精彩评论