go build and installing binaries with go install (module-aware and GOPATH workflows).
1) Build the binary in the module directory
From the module directory (the directory that contains yourgo.mod or package source), run:
- On Linux/macOS run the executable with
./<executable-name>. - On Windows run the
*.exefile by name (for examplecryptit.exe).
2) Running the executable from another directory
If your shell’s current directory is not the one containing the executable, you must either change to that directory or provide the full path to the executable. Example showing an attempt to run from the home directory without a path (fails), then running with a full path:3) Install the binary so it is runnable anywhere
Installing places the compiled executable into a directory that is typically on yourPATH, such as $GOPATH/bin or a directory set by GOBIN. Use go install to compile and install.
- Check
GOPATHandGOBIN:
- If
GOBINis not set and you want to useGOPATH/bin, add it to your shellPATH(example for macOS/Linux):
- From the module directory, install the package:
go install compiles the package and places the resulting binary in GOBIN (if set) or GOPATH/bin.
Verify the binary is in the bin directory and run it from anywhere:
Quick reference: common commands
4) Module-aware installs and versioned installs
If your project uses Go modules (has a
go.mod file), go install without a version will compile and install the package in the current directory into GOBIN or GOPATH/bin. For installing a remote command at a specific version (or the latest), use the versioned form:go install example.com/cmd@latestAdjust your workflow based on your Go version and whether you rely on GOPATH or module-aware installs. See the official Go documentation on go install for more details: https://golang.org/cmd/go/#hdr-Description_of_go_install.5) Troubleshooting tips
- If
cryptitis not recognized after installation, confirm the install directory is on yourPATH(echo $PATH). - If
go installreports module or dependency errors, rungo mod tidyin the module directory to ensure required dependencies are present. - Use
which cryptitorcommand -v cryptitto locate the installed binary.
- build a local binary with
go build, - install it with
go install, - add the install directory to your
PATH, and - run the executable from any directory.