Finding the User Binary Path
If your app needs to know where ~/.local/bin is, this page shows you exactly how to get that path.
Sometimes your application might need to install an executable file on the
user’s system. The XDG spec recommends a specific place for this, which is
usually ~/.local/bin.
The xdgdir crate makes it easy to get this path. This guide will show you how.
Getting the Binary Path
The path to the user’s binary directory is stored in the bin field of the
BaseDir struct. You can get it using either BaseDir::global() or
BaseDir::new(), since this path is not specific to your application.
Here is how you can get it.
use xdgdir::BaseDir;
fn main() {
let dirs = BaseDir::global().unwrap();
println!("User binary path is: {}", dirs.bin.display());
}How it Works
When you run this code, it will print the standard location for user-specific executables.
User binary path is: /home/your-user/.local/binUnlike the other directories like config or data, the binary path is not
configurable with an XDG_ environment variable. It is always resolved as
$HOME/.local/bin. This is part of the XDG specification.
This path is useful if your application has command-line tools that you want to
make available to the user. You could copy your executable to this directory and
then instruct the user to add it to their shell’s $PATH variable if it’s not
already there.