安装去与酿造,并运行的 GoTour

我一直遵循 http://tour.golang.org/,直到我到达第三个步骤,告诉你你可以在你的系统上安装。 之后,我安装了带有 brew 的 Go 语言:

brew install hg
brew install go

然后我通过以下方式下载了手册:

go get code.google.com/p/go-tour/gotour

当我试图发射这枚导弹时,它不认识这个命令:

$ gotour
-bash: gotour: command not found

还有

$ go gotour

还有

$ ./gotour

所以我试着去看那条路,但它是空的,

echo $GOPATH

所以我定义了 GOPATH:

GOPATH=/usr/local/Cellar/go/1.0.2/src/pkg/code.google.com/p/
export GOPATH

现在我可以通过跑步来跑步了

./gotour

但我对自己的工作环境没有安全感,我不是应该能跑过去吗

go run gotour

或只需输入(如本网站 http://www.moncefbelyamani.com/how-to-install-the-go-tour-on-your-mac/所述) :

gotour

我想知道我做事的方式是否正确,因为我是新手,去编程语言。

111355 次浏览

I think I have found the solution, I should have exported:

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

Instead of

GOPATH=/usr/local/Cellar/go/1.0.2/src/pkg/code.google.com/p/
export GOPATH

Since thats where 'go get' puts the binaries (I guess). gotour is working:

$ gotour
2012/10/11 18:35:50 Serving content from /usr/local/Cellar/go/1.0.2/src/pkg/code.google.com/p/go-tour
2012/10/11 18:35:50 Open your web browser and visit http://127.0.0.1:3999/

Btw I based my answer on this post

http://code.google.com/p/go-tour/issues/detail?id=39 where they talk about exporting:

/usr/local/Cellar/go/1.0.2/src/pkg/code.google.com/p/

And the getting started page from go: http://golang.org/doc/install where they say you have to export:

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

I thing you should have set the GOPATH before you go get. Well, at least here in my machine this worked smoothly.

I set the GOPATH to a folder in my home folder.

Hope this helps!

Just an update here - I ran into this same problem, and the previous answers did NOT help. On current (~1.2.2) versions of Go installed by Homebrew, you have to set GOROOT to the following:

export GOROOT=/usr/local/Cellar/go/1.2.2/libexec

I'm a little unfamiliar with the go folder structure, or changes to the go installation via homebrew, so I don't really know why. But - if you're missing what seems like all the core packages, the above should fix.

Installing go 1.4 with homebrew on OSX:

1) Create Directories

mkdir $HOME/Go
mkdir -p $HOME/Go/src/github.com/user

2) Setup your paths

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

3) Install Go

brew install go

4) "go get" the basics

go get golang.org/x/tools/cmd/godoc

5) Start here: https://golang.org/doc/code.html at "your first program"

I put this in my ${HOME}/.bash_profile

export GOPATH="${HOME}/.go"
export GOROOT="$(brew --prefix golang)/libexec"
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"


test -d "${GOPATH}" || mkdir "${GOPATH}"
test -d "${GOPATH}/src/github.com" || mkdir -p "${GOPATH}/src/github.com"

based on golfadas answer but updated to work with old and new versions of brew.

Following a mix of answers above, this is what worked for me on OSX 10.12 (Sierra) and Go v1.7.1 using Homebrew:

I added this from Kosh's answer to my .zshrc or .bashrc:

# Go development
export GOPATH="${HOME}/.go"
export GOROOT="$(brew --prefix golang)/libexec"
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"


test -d "${GOPATH}" || mkdir "${GOPATH}"
test -d "${GOPATH}/src/github.com" || mkdir -p "${GOPATH}/src/github.com"

Then in a new terminal window/tab:

$ brew install go
==> Downloading https://homebrew.bintray.com/bottles/go-1.7.1.sierra.bottle.tar.gz
Already downloaded: /Users/nigel/Library/Caches/Homebrew/go-1.7.1.sierra.bottle.tar.gz
==> Pouring go-1.7.1.sierra.bottle.tar.gz
==> Caveats
As of go 1.2, a valid GOPATH is required to use the `go get` command:
https://golang.org/doc/code.html#GOPATH


You may wish to add the GOROOT-based install location to your PATH:
export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
🍺  /usr/local/Cellar/go/1.7.1: 6,436 files, 250.6M


$ go get golang.org/x/tools/cmd/godoc


$ go get github.com/golang/lint/golint


$ go get golang.org/x/tour/gotour


$ gotour
2016/10/19 12:06:54 Serving content from /Users/nigel/.go/src/golang.org/x/tour
2016/10/19 12:06:54 A browser window should open. If not, please visit http://127.0.0.1:3999
2016/10/19 12:06:55 accepting connection from: 127.0.0.1:52958