Linux – Why Are Custom Programs Installed in /opt, /srv, /usr/local, etc.?

linuxpackage-managementSecurity

The LTS repo is pretty good, but for some reason I prefer the "build from source" method for some programs. One reason is that I get the preferred version (PHP on LTS is on 5.3, whereas I can compile 5.4 from source). Similar is the case for nginx, node.js, etc.

Now I would like to know, why all tutorials insist on installing the programs to the "root-owned" folders such as /opt, /srv, or /usr/local. I find it much easier to install it in my home folder such as:
/home/prahlad/programs/PHP-5.4

One advantage is that I don't need to use sudo to install these programs. Second and a related advantage is security concern. What if (suppose) any of these sources happen to contain malware (though less probable on linux)? Isn't denying them root privilege a good thing to do?

I would like to know one example where it becomes necessary for a program to get installed in a root-owned folder?

Best Answer

The guides tell you to install in /usr/local/ or /opt etc so that others may use them.

If you install in your home directory then only you will have access to them. If you're just compiling for yourself, then this is fine.

Related Question