112

I am developing a set of scripts, which I want to be present for all users, when I set up a server. But I don't want them in the standard locations like /usr[/local]/[bin],[sbin] etc.

Is there some existing convention for where such scripts should be placed?

Seth
  • 57,282
  • 43
  • 144
  • 200
vfclists
  • 1,839
  • 3
  • 16
  • 20
  • For those who may be interested there is an old usenet thread here, https://vb.serverknecht.de/showthread.php?s=a02033e4f14d95407469b81ee34ce870&t=86454&page=1&pp=15, which leads to something more direct http://www.giwersworld.org/computers/linux/linux-file-system.html – vfclists Oct 02 '12 at 19:06

5 Answers5

73

As far as I know there is no place for custom Linux scripts. The directory that should be used for custom install is the /opt directory so it would be the safest option to place them there. But keep in mind that for a script to be able to be used without the full path you need it to be included in the PATH variable.

If you need help changing the PATH variable for all users you can check How do I set PATH variables for all users on a server? which refers you to the /etc/environment file to configure this.

If your concern is to avoid clashes but you don't want to add another route to the PATH variable you could use /usr/local/bin. In my server installation it doesn't have any file so that it could be a easy work-around.

Hope it helps

Davisein
  • 1,041
  • 7
  • 9
57

/usr/local/bin seems to be the conventional place, and this directory should be empty on a fresh installs.

Source: The accepted answer on this question:

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
Rolficus
  • 571
  • 4
  • 2
13

You could place the scripts in /opt/bin and add the location to the PATH.

See:

  1. Linux path environment variable

  2. Permanently add a directory to shell PATH

    For global use in:

    /etc/bash.bashrc
    

    or

    /etc/profile
    
BuZZ-dEE
  • 13,993
  • 18
  • 63
  • 80
  • 2
    In Ubuntu 16.04 there is no `/opt/bin` directory anymore so you have to create it first. In this case you might as well create `/usr/local/scripts` and put that in $PATH. – WinEunuuchs2Unix Jun 11 '18 at 23:55
7

There's also ~/bin, which acts like /usr/local/bin, but for just one user. To enable it, create the ~/bin directory, log out and log back in.

Chai T. Rex
  • 5,126
  • 1
  • 24
  • 48
  • 2
    If the script/executable is only for one user, `~/.local/bin` is a good place, as discussed [here](https://unix.stackexchange.com/questions/36871/where-should-a-local-executable-be-placed). – Matthias Braun May 24 '22 at 17:59
6

There are several places you could put these, typically I place them in /opt/ and update PATH for each user (or globally in /etc/bash.bashrc) so it's available to users. /opt/ is more or less designed for what you're looking to do.

Marco Ceppi
  • 47,783
  • 30
  • 172
  • 197