The Central Go Modules Repository

To use GoCenter:
export GOPROXY=
May 30th 2018
Last Modified


Linux/OSX Build Status Windows Build Status Codecov Go Report Card Go docs

A Go library for getting the user’s home directory without cgo allowing for cross compilation.

This is a tracking fork of mitchellh/go-homedir that is kept up-to-date with changes upstream. The original uses runtime checks to select the logic used. This fork uses go build tags rather than runtime checks. This was suggested in a two PRs (#13, #10) but wasn’t a fit for the specific purpose that the original had been developed for, leading to this fork.


import ""

// Call `homedir.Dir()` to get the home directory of the current user.
homePath := homedir.Dir()

// Call `homedir.Expand()` to expand the `~` in a path to the home directory of the current user.
absPath := homedir.Expand("~/a/path/in/the/home")

Why not use the built in os/user?

The built-in os/user package requires cgo on Darwin (Mac) systems. This means that any Go code that uses that package cannot cross compile. Much of the time the use for os/user is only to retrieve the home directory, which we can do for the current user without cgo. This library does that, enabling cross-compilation.