Skip to main content
In this lesson you’ll learn how to compile a Go module into a native executable and how to install that executable so it can be run from anywhere on your system. This covers both local builds with 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 your go.mod or package source), run:
This command compiles the package in the current directory and produces an executable file in the same directory.
  • On Linux/macOS run the executable with ./<executable-name>.
  • On Windows run the *.exe file by name (for example cryptit.exe).
Example main.go (showing how the program might call your encrypt/decrypt packages):
Build and run locally:
Sample output:

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 your PATH, such as $GOPATH/bin or a directory set by GOBIN. Use go install to compile and install.
  1. Check GOPATH and GOBIN:
  1. If GOBIN is not set and you want to use GOPATH/bin, add it to your shell PATH (example for macOS/Linux):
  1. 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 cryptit is not recognized after installation, confirm the install directory is on your PATH (echo $PATH).
  • If go install reports module or dependency errors, run go mod tidy in the module directory to ensure required dependencies are present.
  • Use which cryptit or command -v cryptit to locate the installed binary.
That’s it — you can now:
  • 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.

Watch Video