96

For example, in Ubuntu, there is always a .local directory in the home directory and .profile includes this line:

PATH="$HOME/bin:$HOME/.local/bin:$PATH"

$HOME/.local/bin does not exist by default, but if it is created it's already in $PATH and executables within can be found.

This is not exactly mentioned in the XDG directory specification but seems derived from it.

What I wonder is if this is common enough that it could be usually assumed to exist in the most common end user distributions. Is it, for instance, in all of the Debian derivatives, or at least the Ubuntu ones? How about the Red Hat/Fedora/CentOS ecosystem? And so on with Arch, SUSE, and what people are using nowadays.

To be extra clear, this is only for $HOME/.local/bin, not $HOME/bin.

Out of curiosity, feel free to include BSDs, OS/X and others if you have the information. :)

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
Stoffe
  • 1,063
  • 1
  • 7
  • 6
  • @ThomasDickey also, you say that Fedora does this at the same time as you haven't encountered it on any system, I assume one of those is a typo. Or I misunderstand? – Stoffe Oct 16 '16 at 16:50
  • 1
    I don't have it in my path, and I certainly won't put it there. (Debian, but xdm/fvwm, neither Gnome nor KDE as desktop). – dirkt Oct 16 '16 at 16:51
  • 1
    I checked for a system which might have it. None of my development accounts use **bash**, and packagers simply aren't thorough enough to notice unless I make a special check (see [newpath](http://invisible-island.net/misc_tools/index.html#item:newpath)). – Thomas Dickey Oct 16 '16 at 16:57
  • 2
    IIRC Ubuntu's `/etc/skel/.profile` up to and including at least 14.04 tests for the presence of a user's `$HOME/bin` and adds it to the `PATH` if it exists; in contrast, 16.04 appears to add both `$HOME/bin` and `$HOME/.local/bin` unconditionally. I don't recall earlier Ubuntus adding `$HOME/.local/bin` at all - but I don't see anything relevant in the `bash` package changelog (which supposedly owns `/etc/skel/.profile`). – steeldriver Oct 16 '16 at 19:08
  • @steeldriver thanks. The upside of the unconditional add is that it doesn't really matter if it doesn't exist, but if you install something that adds it it will start to work without restart or re-sourcing of `.profile`. I also remember it as being conditional earlier. – Stoffe Oct 16 '16 at 20:30
  • 1
    @steeldriver Interestingly, Ubuntu 17.04 does not have `$HOME/.local/bin` added to `PATH` by default. – edwinksl Jul 05 '17 at 17:09
  • 1
    FWIW, none of the BSDs does this. – Kusalananda Sep 01 '17 at 06:36
  • 2
    TIL Ubuntu (20.04) does have `~/.local/bin` in `/etc/skel/.profile` — but that doesn't help if you version your dot files & re-install them into all new accounts for decades on end. Thus, I've been manually adding it (`PATH=~/.local/bin:"$PATH"`), ever since starting python stuff (initially very surprised that python ecosystem chose to use a hidden `~/.local/` for binaries‍♂️) – michael May 20 '20 at 07:14

2 Answers2

91

The ~/.local directories are part of the systemd file-hierarchy spec and is an extension of the xdg-user-dirs spec.

It can be confusing as Debian-derived packages for bash lost the ~/.local path when they rebased to Bash 4.3. They did have it in Bash 4.2.

It is a bug, and a patch has been sitting in the Debian system for a bit now.

This bug is the reason Ubuntu 16.04 had ~/.local in the path and Ubuntu 17.04 did not.

If you run systemd-path as a user, you will see that it is intended to be in the path.

$ systemd-path user-binaries
/home/foo/.local/bin

In theory, the answer to your query is: Any distro that uses systemd or wants to maintain compatibility with systemd.

There is more information in file-hierarchy(7).

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
gdahlm
  • 1,231
  • 10
  • 7
  • 1
    Thanks! Out of pure curiosity, was this also the case during upstart times? Only asking because my memory says it was there earlier than systemd, but it's equally likely I just misremember it! – Stoffe Sep 18 '17 at 03:12
  • 2
    I'd doubt it was before systemd, forever the convention was ~/bin. – pfalcon Jan 14 '18 at 16:29
  • Arrgh, this bug seems to have also arrived in 16.04 courtesy of a backported bash 4.3 – Adrian Apr 05 '18 at 14:58
  • 2
    Works in Ubuntu 18.04. – Daniel Jul 01 '18 at 20:01
  • What about `zsh`? – DLight Jul 02 '20 at 12:46
  • 1
    Debian Bullseye here – neither `bash` nor `fish` load `~/.local/bin` into `PATH`. I needed to add it manually to `~/.profile` for `bash` and for [`fish`](https://fishshell.com/docs/current/tutorial.html#path) I added it [this way](https://stackoverflow.com/a/34401308/1321680): `set -U fish_user_paths $HOME/.local/bin/ $fish_user_paths`. – patryk.beza Feb 05 '21 at 14:29
7

On RPM based distributions, the situation seems to look like this:

  • RHEL 7 - does add it to the end of PATH when you use a login shell. It will work with sudo su -l johndoe but it will not work if you do not use the -l switch.
  • CentOS 7 - see RHEL, it is always following RHEL.
  • Fedora 28 (probably older too) - same as RHEL/CentOS, added to the end of PATH

As for other distributions:

If you want to see those bugs sorted, please do not forget to vote/comment on those as this would highlight the importance of the issue.

AdminBee
  • 21,637
  • 21
  • 47
  • 71
sorin
  • 1,219
  • 2
  • 14
  • 18