5

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 has 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

Andy
  • 3,600
  • 12
  • 53
  • 84

4 Answers4

5

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

justadreamer
  • 2,410
  • 2
  • 21
  • 24
  • 3
    The system property to look for is "user.home", that will give the path to the home directory, like: System.getProperty("user.home") – Kennet Oct 08 '11 at 10:03
5

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

phihag
  • 278,196
  • 72
  • 453
  • 469
  • This is so much more complicated than I first expected, and `home/.program-name` just didn't seem quite right to me, especially considering that I can't see anything else in there at the minute... The reason why I mentioned `usr/lib' is because my other programs seem to be located in there, but on second thoughts, I downloaded them via the Software Center. So if I weren't to use the software center, would the home directory be where I should install my program to? – Andy Oct 08 '11 at 10:13
  • @Andy Actually, it's not as complicated as it looks. Where you install the data your program operates on does **not** depend on whether you install your program manually or with the software center. Notice the path is *not* `/home/.program-name`, but `/home/user/.program-name`. In Java, use `System.getProperty("user.home")` to get that home directory. – phihag Oct 08 '11 at 10:16
  • @Andy Where you store your **program** is a completely different question than where you store your **data**. Put your *program* (JAR files, resources, etc.) into `/usr/local/share/yourprogram`, and executable start scripts into `/usr/local/bin`. Alternatively, put the whole mess into `/opt/yourprogram`. – phihag Oct 08 '11 at 10:18
  • @phihag: I do stand corrected, there is data for other programs in `/home/user/`, so it looks like that will be were I store my data. However, I still can't figure out where to install the actual executable because even with root permissions I can't write to the path you suggested – Andy Oct 08 '11 at 10:27
  • @Andy With root permissions, you can write on every filesystem that's mounted as writable. On a plain Ubuntu, `sudo mkdir /var/lib/yourprogramm` works just fine. If you can't write to, say, `/opt`, ask a new question on [askubuntu](http://askubuntu.com/) why that's the case. Copy and paste a terminal session (or give the screenshot of one) to allow reproducing your problem. – phihag Oct 08 '11 at 10:40
  • @phihag: My bad, I was just going my the fact I could create a folder by right clicking; the terminal line works. However, I don't really want my program to require root permissions to install, so is there another directory that doesn't? Will `/home/user/.program-name` suffice? – Andy Oct 08 '11 at 10:48
  • @Andy No offense, but you may be underestimating the importance of proper packaging. Installing in the software center is easy. If you're fine with the program being only available for the user installing it, you can put it into `/home/user/.program-name/program/`, or skip the dot to make it visible for users. However, please, please, make the path configurable so that advanced users or system administrators can put that mess of a program into `/opt`. – phihag Oct 08 '11 at 10:54
  • @phihag: No offence taken, I am extremely knew to the world of Unix so I probably am underestimating prope]r packaging, etc. and I know that I'm probably silly to rush into something like this! I will take your comments into consideration, and try to make the installation as user friendly as possible when I'm finishing the application. Thanks for all your help! – Andy Oct 08 '11 at 11:00
0

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)

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • I am making a GUI in Java indeed, but I can't seem to write to `/usr/local/bin` even with root permissions, and '/home/user/bin` does not exist! Plus, there aren't any other programs stored in the first directory anyway!? So, I still need a place to store the program executable! Will `/home/user/.program-name` suffice? – Andy Oct 08 '11 at 10:37
-1

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.

Ankit
  • 425
  • 1
  • 5
  • 21
  • To be honest, that definitely doesn't seem right - NO other executables are there!? – Andy Oct 08 '11 at 10:40
  • I had installed numerous Applications & Softwares under $HOME/Softwares directory. It works smoothly for me. What do you mean by other executables. If your working enviorment relates to playing with system files,etc. Then its ok to search for other solutions.. – Ankit Oct 13 '11 at 07:27
  • Where exactly do you mean by "$Home/Softwares directory"? What I mean by "NO other executables" is the fact that only the directory for my users are there at the minute; no other software seems to be stored there... However, I am going to investigate with other software that isn't from the Software Center to see if I can pinch any further idea's... – Andy Oct 13 '11 at 19:17
  • First, "$HOME" refers to this directory "/home/". To see account name, enter "echo $USERNAME". Second, I had a single user desktop computer. As i can understand, you are running mutiple user-servers scenario. In that case, you might be right. – Ankit Oct 14 '11 at 04:44
  • 1
    I think there has been a bit of misunderstanding here for both of us. By "$HOME" I though you were just referring to the `/home/` directory, not including the user's folder - but I do in fact have program files in the $HOME folder! The home folder was actually what I planned to use anyway - `String directory = System.getProperty("user.home") + File.separator + ".my-program"` so thanks.... – Andy Oct 14 '11 at 18:48