this post was submitted on 28 Apr 2025
60 points (96.9% liked)

Linux

53664 readers
484 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

For one user account, I want to have some bash scripts, which of course would be under version control.

The obvious solution is just to put the scripts in a git repository and make ~/bin a symlink to the scripts directory.

Now, it seems on systemd systems ~/.local/bin is supposedly the directory for user scripts.

My question, is mostly, what are the tradeoffs between using ~/bin and ~/.local/bin as directory for my own bash scripts?

One simple scenario I can come up with are 3rd party programs which might modify ~/.local/bin and put their own scripts/starters there, similar to 3rd party applications which put their *.desktop files in ~/.local/applications.

Any advice on this? Is ~/.local/bin safe to use for my scripts or should I stick to the classic ~/bin? Anyone has a better convention?

(Btw.: I am running Debian everywhere, so I do not worry about portability to non systemd Linux systems.)

Solved: Thanks a lot for all the feedback and answering my questions! I'll settle with having my bash scripts somewhere under ~/my_git_monorepo and linking them to ~/.local/bin to stick to the XDG standard.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 51 points 1 day ago (5 children)

I use ~/.local/bin since by linux standard, ~/.local is a user-level /usr/local, which is a override level of /usr

~/bin ends up cluttering the home folder

[–] [email protected] 29 points 1 day ago (2 children)

Another reason to use ~/.local is you can do things like

./configure --prefix=$HOME/.local
make -j$(ncpu)
make install

And then you get your .local/bin, .local/share, .local/include, .local/lib and such, just like /usr but scoped to your user.

and it should mostly just work as well.

[–] [email protected] 7 points 1 day ago

And if there's other users in the machine, it doesn't fuck things up for others Or if it ends up messing something up, it is user-scoped, so its a lot easier to fix than a bricked system

[–] [email protected] 0 points 21 hours ago

Prefix can be just $HOME as well.

[–] [email protected] 7 points 1 day ago (2 children)

If I hand write bash scripts, or for those single binary downloads, they'll go into ~/bin. ~/.local is already used by a ton of packages. This helps a ton when it comes to backups or for just finding where I put stuff.

My ~/.local is 283 GB, it's where podman/docker/etc put containers, it may as well be a system managed folder at that point. My ~/bin is only 120 MB and is a lot simpler to backup/restore/sync to other desktops.

[–] [email protected] 3 points 18 hours ago* (last edited 18 hours ago)

it may as well be a system managed folder at that point.

In a way it is. But user-level system, as opposed to root-level system.

[–] [email protected] 2 points 1 day ago (1 children)

At that point I'd poke around what's in there, cuz there's absolutely a mess in there

[–] [email protected] 4 points 1 day ago

It's really not. Python virtualenv, Steam, libvirt, composer, krita, vulkan, zed, zoxide, systemd, etc. ~/.local is the domain of various installed packages, not my hand crafted scripts.

[–] [email protected] 5 points 1 day ago (1 children)

Another follow up question: Is there any documentation for the linux standard/convention of ~/.local/bin? My initial search about this resulted in nothing which I would call authoritative/definitive.

[–] [email protected] 14 points 1 day ago (1 children)

freedesktop.org defines environment variables that should be used by applications to store their stuff;
[archlinux.org] has a (non-authoritative) summary, but it also provides a [link to the actual specification].

[–] [email protected] 8 points 1 day ago

Thank you so much, bookmarked all of your links! :-)

[–] [email protected] 3 points 1 day ago (1 children)

Mostly this, but also, if you're going to manage many scripts in a system for many users, revision control doesn't help that. Either look at packaging them properly for your distro, or using something Ansible to distribute and manage their versioning on the system to make things easier on yourself.

[–] [email protected] 2 points 1 day ago (1 children)

Me, packaging company software to Alpine Packages so that I can just apk add stuff

[–] [email protected] 1 points 1 day ago

Good practice though. It's pretty much a necessity anymore with supply chain attacks becoming such a thing.

[–] [email protected] 2 points 1 day ago

Thanks! Do you just put the whole .local/bin under source control, do you link your scripts from somewhere else?