Go install not working with zsh
Asked Answered
U

3

22

I feel like an idiot because I've installed this before on macOS and OSX but for some reason I can't see what I'm doing wrong. Please help!!! I've created a directory, ~/go, which will be my workspace. When I run go env from my home directory I get zsh: command not found: go and I know it's because of the following files. What is wrong in my configuration?

~/.bash_profile:

export PATH=$PATH:/usr/local/go/bin

~/.zshrc:

export PATH=$PATH:/usr/local/go/bin
Ullman answered 5/3, 2017 at 21:37 Comment(5)
Have you sourced your ~/.zshrc (or launched a new zsh instance) before running go env?Honeyhoneybee
Yes, I forgot to add that.Ullman
What happens if you run /usr/local/go/bin/go env?Honeyhoneybee
When you run echo $PATH, does it actually contain /usr/local/go/bin?Herl
is this question still unanswered/unresolved?Niggerhead
N
39

If you installed on Mac OS not with home-brew but with the macOS package installer, your GOBIN be in /usr/local/go and GOPATH in $HOME/go, finally in ~/.zshrc:

  export GOPATH=$HOME/go
  export GOROOT=/usr/local/go
  export GOBIN=$GOPATH/bin
  export PATH=$PATH:$GOPATH
  export PATH=$PATH:$GOROOT/bin
Niggerhead answered 26/7, 2019 at 10:10 Comment(2)
And do not use '~' to replace home path :(Nonperishable
I had to add export PATH=$PATH:$GOPATH/bin as well for zsh to pick up installed binariesDebutante
L
22

Below config is working for me,

in ~/.zshrc

export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH
export PATH=$PATH:$GOROOT/bin

You can see the configured details as below then

go env

GOARCH="amd64"
GOBIN="/Users/my-name/golang/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/my-name/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6q/h6nchrdj49zgjfcp8wstj94r0000gn/T/go-build874871088=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
Lovash answered 6/3, 2017 at 1:11 Comment(1)
I wasn't able to execute binaries installed by Go. After adding $GOBIN as well to the path it worked.Subgroup
F
12

Installing go through brew didn't add the global ENV path in the shell profile. So, I had to manually add the following in the ~/.zshrc file, and that was it!

export PATH="$PATH:$(go env GOPATH)/bin"

Note: If you are using bash or another shell, the name of the profile file will be different!

Frontality answered 14/11, 2022 at 11:47 Comment(1)
More clean and simple for someone who just want to run a go binSubarctic

© 2022 - 2024 — McMap. All rights reserved.