Installation
godotenv
can be used as a library in your Go project or as a standalone command-line tool. Installation is straightforward using standard Go commands.
As a Library
To use godotenv
within your Go application, add it to your project as a dependency:
go get github.com/joho/godotenv
This will download the package and make it available for import in your code:
import "github.com/joho/godotenv"
As a Command-Line Tool
godotenv
also includes a command-line utility that can execute a process with environment variables loaded from a .env
file. This is useful for running scripts or applications without modifying your shell's environment.
Go version >= 1.17
go install github.com/joho/godotenv/cmd/godotenv@latest
Go version < 1.17
go get github.com/joho/godotenv/cmd/godotenv
After installation, ensure that your $GOPATH/bin
or $HOME/go/bin
directory is in your system's PATH
. You can verify the installation by running:
godotenv -h