11

Do binaries from this get source immediately?

Do I need to add it to bash profile to be sourced?

If I understand correctly, there are other places for binaries like:

  • /usr/bin
  • /bin
  • /usr/local/bin

Why so many?

Pablo Bianchi
  • 17,371

2 Answers2

15

The bin folders are used for executable programs.

Before Ubuntu 19.10 the folder of /bin itself was used for minimal functionality for the purposes of booting and repairing a system. The /usr/bin folder was used for most of the executable programs. Now /bin is symlinked to /usr/bin so they are now one and the same.

$ lsb_release -r
Release:    20.04
$ ls -al /
total 104
drwxr-xr-x  20 root root  4096 Apr 16 08:28 .
drwxr-xr-x  20 root root  4096 Apr 16 08:28 ..
lrwxrwxrwx   1 root root     7 Oct  2  2021 bin -> usr/bin
$ lsb_release -r
Release:    18.04
$ ls -al /
total 1459924
drwxr-xr-x  24 root root       4096 Feb 24 07:36 .
drwxr-xr-x  24 root root       4096 Feb 24 07:36 ..
drwxr-xr-x   2 root root       4096 Feb 24 07:11 bin

The /usr/local/bin is used for executable programs that are not managed by a distribution package.

The answer for your $HOME/bin folder is contained in the .profile in your home folder (/home/<user>/). It (.profile) is sourced automatically when you log in.

Contained in the .profile file in your home folder are the following sections (It is all about preference):

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

set PATH so it includes user's private bin if it exists

if [ -d "$HOME/.local/bin" ] ; then PATH="$HOME/.local/bin:$PATH"

If either of those bin folders exist they are automatically added to the $PATH when the user logs into their account. It is used for the user's own private executable programs and scripts. They are primarily used for the user or owner of those folders, keeping them private from other users.

Pablo Bianchi
  • 17,371
Terrance
  • 43,712
5

Linux systems are multiuser, even if there is only 1 person using the system. That's worth remembering.

  • /bin was for programs necessary in a minimal environment, no GUI.
  • /usr/bin is for optional programs, but commonly used programs with or without a GUI.
  • /usr/local/bin is for programs that aren't managed by the package manager. This would typically be scripts or custom code or custom compiled code for all users of the system to have access
  • ~/bin/ is for scripts, code, custom code that are for a single user, not everyone. It is also a place that a user can put any code they like if the system admin refuses to install a package or install a non-packaged program into /usr/local.

The major Linux distros follow (mostly) the Linux File System Hierarchy Standards document. A summary of what each directory is for can be found in the wikipedia article by that name. https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard It closely follows the UNIX File System Hierarchy Standards that has been around 30+ yrs. I don't know if UNIX standards are truly standard, but they all seem to be very similar.

The only place that I see where those standards are violated on Ubuntu (and some other distros) is related to /media/ and where ever snap packages go. But that's a different question.

JohnP
  • 728