Skip to main content

Prerequisites

Before installing go-homedir, ensure you have:
  • Go installed (any version with module support)
  • A Go project initialized with go mod init

Installation Steps

1

Install the package

Use go get to install the latest version of go-homedir:
go get github.com/mitchellh/go-homedir
This will download the library and add it to your go.mod file.
2

Import the package

Import go-homedir in your Go code:
import "github.com/mitchellh/go-homedir"
You can now use the library’s functions in your code.
3

Verify installation

Create a simple test file to verify the installation:
main.go
package main

import (
    "fmt"
    "log"
    "github.com/mitchellh/go-homedir"
)

func main() {
    dir, err := homedir.Dir()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Home directory:", dir)
}
Run the test:
go run main.go
You should see your home directory path printed to the console.

Alternative Installation

If you prefer to specify an exact version, you can use:
go get github.com/mitchellh/go-homedir@latest
Or pin to a specific version:
go get github.com/mitchellh/[email protected]
The library has no external dependencies, making it lightweight and fast to install.

Next Steps

Quickstart

Learn how to use go-homedir with a complete working example

Build docs developers (and LLMs) love