7. Go Install

The go install commandarrow-up-right compiles and installs a package or packages on your local machine for your personal usage. It installs the package's compiled binary in the GOBIN directory. (We installed the bootdev cliarrow-up-right with it, after all)

1

Assignment β€” Install the program

Ensure you are in your hellogo repo, then run:

go install

What happens:

  • Compiles main.go

  • Creates a binary named hellogo

  • Puts it in ~/go/bin/hellogo

2
cd ../

Now you're back in your workspace directory.

3

Run the installed program

Run the program from anywhere:

hellogo

Expected output:

hello world

Then submit the CLI tests (from anywhere on your machine):

bootdev test

What is go install?

  • Compiles the program

  • Installs the binary globally on your machine

  • Saves the binary in GOBIN directory (usually ~/go/bin)

  • Makes it available to run from anywhere

go run vs go build vs go install

Command
What It Does
Output

go run main.go

Compile and run immediately

No file saved

go build

Compile to binary in current directory

./hellogo binary

go install

Compile and install globally

~/go/bin/hellogo

Troubleshooting

chevron-right"hellogo not found" β€” your binary isn't in PATHhashtag

This error usually means go install added your binary to your GOBIN directory, but that directory is not in your PATH.

Check your GOBIN:

go env GOBIN

If empty, it defaults to:

echo $HOME/go/bin
# Usually: /Users/yourname/go/bin or /home/yourname/go/bin

Add GOBIN to your PATH:

  • For bash (~/.bashrc or ~/.bash_profile):

echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.bashrc
source ~/.bashrc
  • For zsh (~/.zshrc):

echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.zshrc
source ~/.zshrc
  • For fish (~/.config/fish/config.fish):

echo 'set -gx PATH $PATH $HOME/go/bin' >> ~/.config/fish/config.fish
source ~/.config/fish/config.fish

Verify:

echo $PATH
# Should include: /Users/yourname/go/bin

Now try again:

hellogo
chevron-rightWhere is my binary?hashtag

Find the installed binary:

Real-world usage examples

Install tools globally with go install (keep the full URLs and versions as shown):

Project structure after install

Local:

Global:

Key takeaways

  • go install compiles and installs globally.

  • Binary goes in $GOBIN (usually ~/go/bin).

  • Add GOBIN to PATH to run from anywhere.

  • Commonly used for installing tools and utilities.

  • Different from go run (temporary) and go build (local).