44

I wanted to put my work files (code) in /usr/local/src, but I think it's already a folder that has some other semantic meaning.

What is that? Should I put source code there, or is there a better place?

Edit - I am the sole user and admin of the machine, and I don't want to use my home directory because it's on an NFS drive.

ripper234
  • 31,763
  • /usr/src as of Ubuntu 23.10 appears to be a location where you are supposed to dump source code for packages you have downloaded debug symbols for: https://askubuntu.com/questions/487222/how-to-install-debug-symbols-for-installed-packages/1434174#1434174 which allows you to debug crashes on packaged software with GDB. – Ciro Santilli OurBigBook.com Jan 15 '24 at 07:42

2 Answers2

49

According to Linux FHS, /usr is the location where Distribution-based items are placed and /usr/local is the location where you'd place your own localized changes (/usr/local will be empty after a base install). So, for example, if you wanted to recompile an Ubuntu package from source, their package manager would place the source for package in /usr/src/{package dir}. If you downloaded a program not managed by your distribution and wanted to compile/install it, FHS dictates that you do that in /usr/local/src.

EDIT: Short answer, yes, put your code in /usr/local/src.

Sean C.
  • 2,390
17

It depends on what you're doing with that source. If it's for reference, yes, that's a good place. /usr/local is reserved for software installed locally by the sysadmin. So, if you want to install software along with source files (for other programs to use or for people to look at), that's good.

It's not meant, however, to be a workspace. Since it is local, you can do whatever you want, of course, but this isn't designed to be the place to put your software development tree.

That should, really, be in a code repository (possibly in /srv/sourcerepo or something), and then developers would check out their own working copies into their home directories.

mattdm
  • 40,245
  • 1
    I second what mattdm says above. I usually use /usr/local/src as a good place for downloading third party source code (eg for patching and rebuilding packages), not my own source code, which as matt says, should be under /srv/... (though I usually use /srv/vcs/sourcerepo). And mirrored remotely, of course. – Faheem Mitha Apr 07 '11 at 18:44
  • @Faheem - my home directory is on an NFS drive, so I definitely don't work my source branch to be there (too slow). – ripper234 Apr 07 '11 at 18:50
  • I think this is the better answer. Me for example, i have web applications in /srv/http, and their repos in /srv/git. now im looking for dev support tools. I was totally leaning on /usr/local/appname or /usr/local/src even better, until i read this. This gave me the reason i knew in the back of my mind. This is indeed a worktree, you caught me. So, what if i instead put it there, then clone it into ~/src build it there, then and push it to its upstream which is the place thats added/or-in the path to run the dev tools. I just dont like the idea of /srv, since its not being served. – Brian Thomas Aug 23 '16 at 04:31
  • What, then, does srv stand for? – SherylHohman Feb 07 '19 at 19:32
  • 1
    @SherylHohman It doesn't really stand for anything (it's not an acronym) but we chose it to imply "service". See the FHS which says "/srv contains site-specific data which is served by this system". – mattdm Feb 07 '19 at 19:46
  • 1
    @SherylHohman, taking from the folder description from the Linux Documentation Project, I would guess "srv" stands for "serve", "service" or something (anything?) related to the "serv-" root. – Waldir Leoncio Sep 30 '20 at 06:25
  • 1
    @WaldirLeoncio Yeah, that's an older version of the same document I linked. I was involved in getting that added to the standard, and as I remember, it's not really that it stands for "server" or "service" but it's definitely meant as a mnemonic for that. – mattdm Oct 02 '20 at 17:17
  • If I decide to patch and compile the kernel, should I put its source code in /usr/src or rather in /usr/local/src and why? After all, I install and maybe compile the Kernel as root, since it requires sysadmin privileges anyways. Also, if I fork a dwm to change its config and recompile its source, it becomes my own forked source code, is this then considered my code base? Should it be checked out to $HOME/whatever/dwm or can it be checked out to /usr/local/src/dwm? – Martin Braun Feb 16 '23 at 12:15
  • 2
    My answer was over a decade ago, but I think it still stands. /usr isn't meant to be a workspace. Check out and compile into your home directory. Build as a regular user. Install as root when done. – mattdm Feb 16 '23 at 18:54