I want to install a program in Linux and run it as a daemon. (Team Speak 3 in this case, but the question is general in nature). There is no package provided, only tarred binaries.
Where in the directory structure should I put such a program by convention?
On the web I found that /opt is for “optional addon apps”, while /usr is for “user programs”.
I found one tutorial suggesting /opt while another suggested /usr.
So which one is “more correct”?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The “more correct” depends on your distribution. You should check your distribution’s guidelines on where to put software that isn’t managed by the package manager (often /usr/local) OR on how to create your own package for it.
As you said TeamSpeak just put everything in one folder (and may not be easy to reorganise), yes /opt/ is probably best.
(But, for instance, in Archlinux, the package manager can install there, so I’d still make a PKGBUILD to install in /opt.)
Also distributions usually try to follow the Filesystem Hierarchy Standard, so this is where to look for more generic convention.
Method 2
If you will be compiling your own software then you ultimately control the installation location. By convention, software compiled and installed manually (not through a package manager, e.g apt, yum, pacman) is installed in /usr/local. Some packages (programs) will create a sub-directory within /usr/local to store all of their relevant files in, such as /usr/local/openssl. Other packages will install their necessary files into existing directories such as /usr/local/sbin and /usr/local/etc. These are simply default locations and can be changed during compilation.
When you are compiling software, the installation location can be specified by using the --prefix= option when running ./configure. It is highly recommended that you look at all of the available options for your package by running $ ./configure --help | less. Additionally, browsing the INSTALL and README documents provided with your package is a good idea. They tend to include installation instructions and dependency information that is specific to the package.
It should also be noted that although you can store software anywhere, according to the FHS, source code for locally installed software should be stored in /usr/local/src Standardizing where you store your source trees will allow you to easily locate a tree if you need to copy a stock configuration file or binary. Even though some packages use it, your source code should not be stored in /usr/src as that is designated for system software such as the kernel.
Finally, you need to ensure that your installation location is included in your $PATH. If you decide to install your package in /opt but it’s not in your $PATH your shell won’t find the executables and you will have to use the absolute path to invoke your programs. Here are some great discussions from AU about configuring your $PATH
Additional reading: man hier
Method 3
The Linux Standard Base and the Filesystem Hierarchy Standard are arguably the standards of where and how you should install software on a Linux system and would suggest placing software that isn’t included in your distribution either in /opt or /usr/local/ or rather subdirectories therein (/opt/<package> /opt/<provider> /usr/local/bin).
Best practice is to convert software you download to a installable software package native to your distribution, for instance dpkg or rpm formats. That will facilitate reporting, upgrading and cleanly removing the software.
Method 4
~/.local/bin
This is defined in systemd’s standard which has the following to say about the directory’s contents:
Executables that shall appear in the user’s
$PATHsearch path. It is recommended not to place executables in this directory that are not useful for invocation from a shell; these should be placed in a subdirectory of~/.local/lib/instead. Care should be taken when placing architecture-dependent binaries in this place, which might be problematic if the home directory is shared between multiple hosts with different architectures.
Depending on your distribution, you might have to add the directory to your path by putting this in your ~/.bashrc:
PATH=$PATH:~/.local/bin
See also: Which distributions have $HOME/.local/bin in $PATH?
Method 5
I had the same question while installing Eclipse via the Eclipse installer.
I noticed that Gimp, Perl and Vim are installed in the /usr/share folder and decided to install it there.
Method 6
Binaries go in the bin folder by common conventions, how you would organize your package structure is up to you, I can think of /opt/<prog_name>/ if it is just a list of binaries.
Method 7
There are two ways programs can be installed, depending on how they are packed.
-
Via the software manager (apt, synaptic, Gdebi etc.) – the program is in a form of package, usually .deb or rpm. Software managers in most cases handles dependencies and will install binaries usually into
/usr/bin, config files into/etcand so on. They may also create a config file for the program in your home, usually~/.foo. If you can edit this file, you can also easily change settings for your session this way. When you remove the package, the manager will find all the files and cleanly remove them (it stored all the locations in a special text file). But it may preserve some config files, for example the one in your home folder. -
You download a program (usually compressed) in a form of pre-compiled binary files for your architecture. The executable file of the program is usually in a single folder next to other files (dynamically linked libraries etc.) This whole folder can be copied, with root privileges, either to
/optor/usr/binand could, if permissions allow, be used by any user. I myself put the folders with binary files into my home folder to~/bin. Now you should be able to run the program by invoking its bin file.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0