2

like most folks, I'm occasionally installing things or writing/using scripts that are sourced from outside my distros repositories or "handmade", so they might not end up in the systems default path, or should not be added to that.

Now there is different ways to proceed.

Something that I might only want to run occasionally or only need to run in a certain directory anyways can stay as it is since cd ~/stuff/fancyapp and then ./fancyexecutable is good enough.

But sometimes, I might want to be able to simply do something like backup.sh from whatever location I'm in or other programs need to be aware of a certain executable, and for this, I can update my $PATH with something like PATH=$PATH:~/bin/backup/, export PATH and restarting my session. However, this leads me to the issue of either having a "home bin" where I move/symlink every executable into ~/bin/, or when I want to have an oderly home bin, having to add every single subdirectory to my path. (Or, I could hack something together to make path recursive)

So what is the proper, recommended and secure way of dealing with your own bin that will have multiple executables and subdirectories?

  • May want to look at GNU Stow. – Mark Plotnick Nov 28 '17 at 17:44
  • Looks interesting, but I'd prefer to "solve" this issue without any additional tools. – JC_CL Nov 30 '17 at 8:17
3

I install all the software built locally into /home/user/.local directory. This directory basically copies the directory structure of /usr as you can see:

> ls ~/.local
bin  etc  include  jars  lib  lib64  libexec  man  share

You can point the build tools to set this directory as the install prefix. Some tools use the value of environment variable PREFIX to determine the install location, so it's a good idea to set that as well, But don't rely on it.

Note that you'll have to set the value of several environment like PATH, LD_LIBRARY_PATH, PKG_CONFIG_PATH, CLASSPATH accordingly.

  • This seems like a valid approach for things you actually built, but with some random bash scripts or some premade executables out of some downloaded tarballs/zips this goes back to my initial "where to put things/which folder(s) to add to PATH" issue. – JC_CL Nov 28 '17 at 14:22
  • @JC_CL you could put them in any folder and add that to the path. What kind of security vulnerability might that create? – saga Nov 28 '17 at 14:44
  • Apparently, "hacking" PATH to be recursive is a security risk (see link in Q), and I am currently just adding the needed folders to the path, but this is a kinda messy solution, it appears to me, so I'm looking for a best option. – JC_CL Nov 30 '17 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.