2012年11月29日 星期四

Golang: Create your local environemnt

Generally, you can install Go from the package installer that Go provides.
But as you need to install packages, you need root permission to install packages into the default system GOROOT path (like /usr/local or /opt/local.. etc)
You can provide your own GOPATH to avoid this kind of problem.
First, you should create a directory structure like this:
  ~/mygo
  ~/mygo/pkg
  ~/mygo/src
  ~/mygo/bin
Then, export this path (~/mygo) to your GOPATH in your .bashrc or .zshrc file:
  export GOPATH=$HOME/mygo:$GOPATH
And the bin path of Go:
  export PATH=$HOME/mygo/bin:$PATH
Done. Now you can install packages into your own local go environment. for example:
  go get https://bitbucket.org/mikespook/gearman-go
which won't require you to sudo.
If you need to install packages from local, you need to move your package source to ~/mygo/src directory, then build the package there, or Go will complain about go install: no install location for ...