Overview
- install Go from go.dev
- configure your terminal
$PATH
- configure
$GOPATH
Installing Go Tools
To install Go, I downloaded it from go.dev.
My setup is an ARM Mac laptop and my terminal is zsh
After installing, I ran into an issue running go version
because it couldn’t find the installation path.
Go gets installed at ~/usr/local/go/bin
but my ~/.zshrc
file didn’t have the path, so it was looking for it in the wrong directory. The solution was to append my zsh path variable with the correct route.
However, the book instructed me to add the path to the .profile with these commands after opening the gzipped files with tar:
tar -C /usr/local -xzf {your go file here}
echo 'export PATH=$PATH:/usr/local/go/bin' >> $HOME/.profile
source $HOME/.profile
I found out that .profile
is specifically for bash
, and I’m using zsh
. So I ended up just manually adding this to my .zshrc
file
export PATH="/usr/local/go/bin/":$PATH
Now, I am able to successfully run go version
and all other commands
The Go Workspace
When you run go install
commands, Go looks for a $GOPATH
to run find those binaries to run.
We want to set our $GOPATH
to $HOME/go
. Then our directory will end up looking something like this:
$HOME/go/
├── bin/
├── pkg/
└── src/
├── github.com/
│ └── spf13/
│ └── cobra/
└── myproject/
└── main.go
Again, we need to update our .zshrc
file to set up that $GOPATH
variable, and append it to our terminal’s $PATH
variable:
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin