-
Star
(572)
You must be signed in to star a gist -
Fork
(133)
You must be signed in to fork a gist
-
-
Save vsouza/77e6b20520d07652ed7d to your computer and use it in GitHub Desktop.
# Set variables in .bashrc file | |
# don't forget to change your path correctly! | |
export GOPATH=$HOME/golang | |
export GOROOT=/usr/local/opt/go/libexec | |
export PATH=$PATH:$GOPATH/bin | |
export PATH=$PATH:$GOROOT/bin |
# Set variables in .zshrc file | |
# don't forget to set path correctly! | |
export GOPATH=$HOME/golang | |
export GOROOT=/usr/local/opt/go/libexec | |
export PATH=$PATH:$GOPATH/bin | |
export PATH=$PATH:$GOROOT/bin |
# Set variables in config.fish file | |
# don't forget to set path correctly! | |
# GOLANG configurations | |
set -x GOPATH $HOME/golang | |
set -x GOROOT /usr/local/opt/go/libexec | |
set PATH $GOPATH/bin $GOROOT/bin $PATH |
echo "Please enter your golang path (ex: $HOME/golang) :" | |
read gopath | |
echo "Please enter your github username (ex: vsouza) :" | |
read user | |
mkdir $gopath | |
mkdir -p $gopath/src/github.com/$user | |
export GOPATH=$gopath | |
export GOROOT=/usr/local/opt/go/libexec | |
export PATH=$PATH:$GOPATH/bin | |
export PATH=$PATH:$GOROOT/bin | |
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
brew update | |
brew install go | |
brew install git | |
go get golang.org/x/tools/cmd/godoc | |
go get golang.org/x/tools/cmd/vet |
I'm getting that error as well.
line 26: syntax error: unexpected end of file
Any ideas?
package golang.org/x/tools/cmd/vet: cannot find package "golang.org/x/tools/cmd/vet" in any of:
/usr/local/opt/go/libexec/src/golang.org/x/tools/cmd/vet (from $GOROOT)
/Users/xavi/golang/src/golang.org/x/tools/cmd/vet (from $GOPATH)
Anyone else with this error?
@mjreed09 and @xavipedrals
try with
command -v brew >/dev/null 2>&1 || { ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"; };
its missing semicolons
Thank you for the help and instructions @vsouza, very useful.
A couple of points based on my experiencing of carrying out these instructions on OSX 10.11.3
- I could not find .bashrc so I placed the exports inside .bash_profile
- I already had homebrew and git and when I run the ./install.sh it upgraded homebrew and give error while trying to install git because it was already installed.
- At the end I got the following
package golang.org/x/tools/cmd/vet: cannot find package "golang.org/x/tools/cmd/vet" in any of: /usr/local/opt/go/libexec/src/golang.org/x/tools/cmd/vet (from $GOROOT) /Users/Raf/workspace/golang/src/golang.org/x/tools/cmd/vet (from $GOPATH)
I checked /users/Raf/workspace/golang/src/golang.org/x/tools/cmd/vet and it exist, so not sure why the error if it already exist.
I tried the go run helloworld.go and I got the result.
Regarding godoc
and vet
: https://golang.org/doc/go1.2#go_tools_godoc
I didn’t want to manually edit the paths in the .*rc so I added the following to the install.sh
:
grep GOPATH ~/.zshrc || sed "s|^export GOPATH=.*|export GOPATH=${gopath}|g" >> ~/.zshrc <<EOF
export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/golang
export PATH=\$PATH:\$GOPATH/bin
EOF
It’s not perfect but works for me. I only use zsh..maybe someone has time to do like if $SHELL = 'zsh' .. else ..
Great Job! Thank U!
@rmldsky
According to https://golang.org/doc/go1.2#go_tools_godoc :
$ go get code.google.com/p/go.tools/cmd/godoc
package code.google.com/p/go.tools/cmd/godoc: unrecognized import path "code.google.com/p/go.tools/cmd/godoc" (parse https://code.google.com/p/go.tools/cmd/godoc?go-get=1: no go-import meta tags)
$ go get code.google.com/p/go.tools/cmd/vet
package code.google.com/p/go.tools/cmd/vet: unrecognized import path "code.google.com/p/go.tools/cmd/vet" (parse https://code.google.com/p/go.tools/cmd/vet?go-get=1: no go-import meta tags)
BTW, we should set only $GOPATH and $PATH (for brew at least), $GOROOT integrated inside go's binary.
# cat ~/.bashrc
export GOPATH=$HOME/golang
export PATH=$PATH:/usr/local/opt/go/libexec/bin
# ls -all /usr/local/opt/go
lrwxr-xr-x 1 orangeudav admin 18 12 сен 21:57 /usr/local/opt/go -> ../Cellar/go/1.7.1
# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/orangeudav/golang"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.1/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/g8/551vgzq10c7bdq3k7zby5_gw0000gn/T/go-build818624631=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Found that you don't need to install godoc
Why is brew install mercurial
installed?
@Gerst20051 Was the old golang setup, Isn't necessary anymore.
Thanks a lot for that script.
It can be updated and improved slightly but it is highly required. :-D
I can't understand why there isn't anything like that from the Golang website?
Either MacOS Package and an install script or via Brew and an install script.
Thanks a lot for your work. That was really helpful.
thanks a lot this gist save my life lol
BTW, we should set only $GOPATH and $PATH (for brew at least), $GOROOT integrated inside go's binary.
# cat ~/.bashrc export GOPATH=$HOME/golang export PATH=$PATH:/usr/local/opt/go/libexec/bin # ls -all /usr/local/opt/go lrwxr-xr-x 1 orangeudav admin 18 12 сен 21:57 /usr/local/opt/go -> ../Cellar/go/1.7.1 # go env GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/orangeudav/golang" GORACE="" GOROOT="/usr/local/Cellar/go/1.7.1/libexec" GOTOOLDIR="/usr/local/Cellar/go/1.7.1/libexec/pkg/tool/darwin_amd64" CC="clang" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/g8/551vgzq10c7bdq3k7zby5_gw0000gn/T/go-build818624631=/tmp/go-build -gno-record-gcc-switches -fno-common" CXX="clang++" CGO_ENABLED="1"
thanks!
@dagadbm good
Big thank you
Thanks!
Setup for fish users
# GOLANG configurations set -x GOPATH $HOME/golang set -x GOROOT /usr/local/opt/go/libexec set PATH $GOPATH/bin $GOROOT/bin $PATH
thanks bro
worked for me by changing
export GOPATH=$HOME/golang into export GOPATH=$HOME/go
Anyone on Apple silicon will need to instead use the updated prefix for Homebrew, i.e. /opt/homebrew
instead of /usr/local
. The remainder of the paths will be the same.
The .zshrc
example would therefore be:
# Set variables in .zshrc file
# don't forget to set path correctly!
export GOPATH=$HOME/golang
export GOROOT=/opt/homebrew/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
@javaducky OMG, you saved my life!!!
/opt/homebrew
instead of/usr/local
for M1
I wish I read this at the beginning 😭
@javaducky thanks man - super helpful!
better get the prefix via brew --prefix
Anyone on Apple silicon will need to instead use the updated prefix for Homebrew, i.e.
/opt/homebrew
instead of/usr/local
. The remainder of the paths will be the same.The
.zshrc
example would therefore be:# Set variables in .zshrc file # don't forget to set path correctly! export GOPATH=$HOME/golang export GOROOT=/opt/homebrew/opt/go/libexec export PATH=$PATH:$GOPATH/bin export PATH=$PATH:$GOROOT/bin
👍🏼
yeah I used go env first, and then used this as a guide to modify my .zshrc
, trusting that go env
was correct. Annoyingly GOBIN was ''
though, so I'm not 100% sure the stability of homebrew golang recipe.
For Apple M3 with .zshrc
Here is the path I have used.
Make sure to change the Go Version according to your local setup and validate the existence of these directories
export GOPATH=$HOME/go
export GOROOT=/opt/homebrew/Cellar/go/1.23.3/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
GOROOT
does not need to be set with go versions after 1.0. Setting it can cause errors. Go knows where it lives.
If you want to install packages with go, then also set GOPROXY
and GOSUMDB
.
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
export GOPROXY=https://proxy.golang.org,direct
export GOSUMDB="sum.golang.org"
Apple silicon, macOS Sequoia, 15.6.1 (24G90), Homebrew 4.6.7, go 1.25.0
I get the following error after inserting path and GitHub username.
mkdir: /Users/username/GitHub/Go: File exists /Users/username/Downloads/77e6[...]b8b9c/install.sh: line 26: syntax error: unexpected end of file
Any idea what this means?