Where to place tools


Just started with go and I’m trying to wrap my head around the tools that exist with go. I’m thinking about things such as golint, govendor and guru and the likes. So far I’ve been working on one isolated project but it’s going to branch out to be a general library several other projects will be depending on. That’s when the layout starts looking pretty odd to me, for instance I’m using “goimports” in emacs to format my code, and thus I need to have it in my path somehow. What I’ve started doing is “go getting” the tools I need and then copy the binaries (and in the case of oracle.el also the source file) to $GOROOT.

My gut feeling is that I’ve misunderstood how “the right way” to do things is for go. So, can someone please use a few minutes to explain to me The Right Way to do things in go?


I don’t know what “the right way” exactly is either, and I never had this problem, since I use Atom and it installed all dependencies for me. But if I understand your problem correctly, you need to have your tools in your path. That seems like it is solved by the recommendation I’ve read somewhere (I think it was the Getting Started guide on golang.org) to have your $GOPATH/bin in your path, which makes it easy to just compile and run your programs - and automatically has your tools available then too.

A common way of handling this is to have GOPATH=~. You then keep your source in ~/src and binaries get installed to ~/bin. Add ~/bin to your PATH and you’re good to go.


That is a good tip! But it does not really matter where you set your $GOPATH, because you can just include $GOPATH/bin in your $PATH anyway. :slight_smile:

From my ~/.bashrc


Thanks everyone for the answers!

Coming from perl/java/python/… it’s a bit of a new way of thinking for me about the project setup and the development environment. More used to each repository being completely independent and the dev tools being installed globally. Your answers and following up with reading this blog post (and the video) really helped me understand the “go way” of doing it.

I’ve now got some problems with govendor but I’ll wrestle it for a while before asking for help again.

it’s also well documented on golang site.


Is there a reason why you’re declaring GOROOT?

using binary release from golang.org on Linux somewhere in $HOME require GOROOT properly set.

Look closely, I’m not exporting GOROOT.

even that.

without export seems not to work

george@george-AO756:~/go-programs/src/HelloWorld$ tail -4 $HOME/.bashrc
george@george-AO756:~/go-programs/src/HelloWorld$ go build
go: cannot find GOROOT directory: /usr/local/go

with export

george@george-AO756:~/go-programs/src/HelloWorld$ tail -3 $HOME/.bashrc
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/go-programs
george@george-AO756:~/go-programs/src/HelloWorld$ go build
george@george-AO756:~/go-programs/src/HelloWorld$ ./HelloWorld 
Hello World!

tested with go version go1.6.2 on U14.04.

My go install is in $HOME/go. All that line does is making sure $HOME/go/bin is in my path, followed by $HOME/bin.

edit: It looks like you’ve unpacked the Go distribution from golang.org into $HOME/go. Don’t do that. Follow the instructions on the website and you won’t have to set $GOROOT. If you have to set $GOROOT, you’ve made a mistake somewhere.

Whoops, didn’t see you’re not exporting. The naming just confused me :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.