Skip to content

Instantly share code, notes, and snippets.

@ivanzoid
Created August 26, 2012 10:43
Show Gist options
  • Save ivanzoid/3477252 to your computer and use it in GitHub Desktop.
Save ivanzoid/3477252 to your computer and use it in GitHub Desktop.
Aumatically setup $GOROOT in HomeBrew
#
# Place this code to your .profile, .bashrc, .bash_profile or whatever
#
program_exists () {
type "$1" &> /dev/null ;
}
if program_exists go; then
function setupGOROOT()
{
local GOPATH=`which go`
local GODIR=`dirname $GOPATH`
local GOPATH_BREW_RELATIVE=`readlink $GOPATH`
local GOPATH_BREW=`dirname $GOPATH_BREW_RELATIVE`
export GOROOT=`cd $GODIR; cd $GOPATH_BREW/..; pwd`
}
setupGOROOT
fi
@itorres
Copy link

itorres commented Mar 2, 2014

wouldn't it be easier a simple?

eval `go env|grep GOROOT`

Edit: even easier:

export GOROOT=`go env GOROOT`

@abdullin
Copy link

@itorres Thanks a lot for the tip. It solved my problem with godef and a brewed go install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment