I like to keep my own projects and the source code for foreign projects I just compile to use them separate. While I could of course achieve this in my home directory, I thought why not use /usr/local/src for the latter?
The problem is that /usr/local/src is owned by root. I’m pretty sure that running build scripts and the like with super user privileges is a very bad idea. One obvious solution would be to simply change the owner of /usr/local/src to myself.
Before doing that however I just wanted to ask if this would be considered good practice or if I’m attempting to do something weird here.
Changing the ownership of /usr/local/src seems a very bad idea. The system sometimes puts things there so the changed ownership might impact software installation and updates.
In general, everything on the system except your home directory is owned by root or one of the other user accounts under which certain apps run.
To me it would seem more reasonable to do the development under your home directory where you are free to create files and directories as needed. Once the app is properly created and compiled, then installation under /usr/local would be appropriate. For distribution the new app should probably be installed under /usr/local as well.
Hm ok, I guess I stick to home then. Just out of curiosity though, what is the purpose of /usr/local/src? I think I’ve never witnessed the system to put something in there.
I think that when a user installs the source code for certain apps that may require local compilation it may be placed there.
I have never used it, but in general it is not wise to change ownership of any system directory (which is everything except /home or (on fedora) /run/media/USER/xxx (when a removable device is attached.)). A user may also create a subdirectory under /mnt and change the ownership of that subdirectory mount point if they choose.
For /usr/local, it says this: “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 may be used for programs and data that are shareable amongst a group of hosts, but not found in /usr.” → OK, so machine-specific but similar to /usr and safe from system updates.
It goes on to say there must be a src subdirectory or symlink for “Local source code”. That is less helpful.
The definition for (non-local) /usr/src specifies this: “Source code may be placed in this subdirectory, only for reference purposes.[37]” and footnote [37] clarifies: “Generally, source should not be built within this hierarchy.”
Based on the similarity between /usr and /usr/local, I would guess that the same applies for /usr/local/src, then.
I definitely like to use my home for that and archive it in a local/private “cloud”. Or in a public cloud to share it with others.
In .bashrc it prepares you an environment by default in:
# User specific environment
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]; then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH
Just create the folders and you are good to go.
You still can manage the source in a src subdirectory while compile it back into bin, to have it on your fingertips when needed.