Why go-homedir?
The built-inos/user package requires cgo on Darwin systems, which prevents cross-compilation. For the 99% of use cases where you just need the home directory, go-homedir provides a pure Go solution that works everywhere.
Cross-Platform
Works seamlessly on Windows, macOS, Linux, and Plan 9
No cgo Required
Pure Go implementation enables cross-compilation
Built-in Caching
Optimized performance with automatic result caching
Simple API
Just two main functions: Dir() and Expand()
Quick Example
Key Features
Cross-platform home directory detection
Cross-platform home directory detection
Automatically detects the home directory on Windows (using USERPROFILE, HOMEDRIVE/HOMEPATH), Unix-like systems (using HOME environment variable and getent), macOS (using dscl), and Plan 9.
No cgo dependency
No cgo dependency
Unlike os/user, go-homedir doesn’t require cgo, making it perfect for cross-compilation scenarios where cgo would be problematic.
Performance optimization with caching
Performance optimization with caching
Results are cached automatically to avoid repeated system calls. You can disable caching globally with the DisableCache variable or clear the cache with Reset().
Tilde expansion
Tilde expansion
The Expand() function makes it easy to convert paths like ~/Documents to absolute paths by replacing the tilde with the actual home directory.
Next Steps
Installation
Add go-homedir to your Go project
Quickstart
Get up and running in minutes
API Reference
Explore the complete API documentation
Examples
See real-world usage examples