Is there a standard location in Linux for holding source files for example OpenSSL. I am building Nginx from source with non default version of OpenSSL. I need to download and untar OpenSSL and I did it in home directory. Now, I wonder is there a standard location in Linux maybe /opt ?
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
Whenever you ask yourself something like this, check out the Filesystem Hierarchy Standard (FHS).There, you will find the following entry:
usr/src : Source code (optional)
Purpose
Source code may be placed in this subdirectory, only for reference purposes
So you can put your source files in subdirectories of /usr/src. That said, this is an optional directory so you can really keep them wherever you like. Source code is not relevant after you’ve compiled it into an executable so the system will never require the source of something to be accessible at a specific location.
In conclusion: /usr/src is a pretty standard location but feel free to choose your own if you prefer.
Method 2
/usr/local/src is a safe place to keep source code, and build it too. The FHS says:
Directory Description src Local source code
and also
The /usr/local hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated.
It’s not clear what “Local source code” means, but it’s clear the system isn’t going to try to place anything in /usr/local/src, unlike /usr/src, so there seems to be little downside to putting code there.
In fact, I have mine on a separate filesystem:
Filesystem Size Used Avail Use% Mounted on /dev/mapper/data-local_src 79G 46G 30G 61% /usr/local/src
Note: at least on Debian, your user needs to be added to the staff group in order to write to /usr/local.
Method 3
If by “standard” you mean conventional, then the place to unpack and build source code is your home directory. Such files are expected to be transient, deleted when you are done, or kept if you like, organised however you please. Your home directory is your area to play with all this kind of stuff.
If you do wish to keep them afterwards, for reference, the “Filesystem Hierarchy Standard” recommends /usr/src. However, this is a guide not a law; and, if you were to get into this habit then venture onto a non-Linux system, you are liable to cause trouble by following it. For example, on a BSD system, base system sources are kept there and you really don’t want to be messing with those. Even on Linux you may run the risk of mingling with any source stored by package managers, which is not desirable.
I would recommend avoiding /usr/src overall. There’s no obvious benefit to keeping anything there at all, and potential risk if you confuse its intended meaning.
Method 4
You can use /usr/src as this place sound reasonable and rpm based distributions use it to store there content of srpm packages. But any other place like /opt, /usr/local, ~/src is good
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