~4 min read|
In A Tour of Go, one of the options is to run the tour offline.
The instructions seem simple enough:
go get golang.org/x/tour
First things first:
workspaces seem to have been deprecated with the introduction of modules in v1.13+.1
Why does any of this matter? Because when I followed the instructions:
stephen@Stephens-MBP-2 ~ % go get golang.org/x/tour stephen@Stephens-MBP-2 ~ % $HOME/go/bin/tour
The tour successfully downloaded, and I was able to run the binary… but, I couldn’t execute anything.
Trying to run the
Hello, world, I got the message:
Program exited: signal: killed.
First, let’s look at a few things:
/usr/local/go/binshould be automatically available in the
PATH. Checking that, it appears that’s true!
$ echo $PATH /Users/stephen/.nvm/versions/node/v12.16.1/bin:/Users/stephen/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/stephen/.cargo/bin
go get), where did that save and install? Not in
/Users/stephen/go- this is because that’s my
$ go env ... GOBIN="" GOPATH="/Users/stephen/go" GOROOT="/usr/local/go" ...
In my haste to get started, I didn’t fully comprehend Go’s How to Write Go Code, specifically, in describing the installation of a
hello.go it reads:
$ go install example.com/user/hello $
This command builds the
hellocommand, producing an executable binary. It then installs that binary as
$HOME/go/bin/hello(or, under Windows,
%USERPROFILE%\go\bin\hello.exe). The install directory is controlled by the
GOBINenvironment variables . If
GOBINis set, binaries are installed to that directory. If
GOPATHis set, binaries are installed to the
binsubdirectory of the first directory in the
GOPATHlist. Otherwise, binaries are installed to the bin subdirectory of the default
What’s all this mean? Well, it means that by default, the Go binaries will be saved in
/Users/stephen/go/bin, (which is also often written as
We can make executing Go binaries a much simpler process then by adding this to our PATH, like so:
... export PATH="$PATH:$HOME/go/bin" # This adds User Installed Go Binaries to PATH
Okay, so that makes it simpler to run the tour, which can now be done as:
$ go get golang.org/x/tour $ tour
None of these hold the answer, yet, however.
Even though it’s now easier to run the tour, it still doesn’t actually execute the Go code.
To get it working, however, manually building and installing does seem to work:
$ go get -d golang.org/x/tour // Not necessary if the source code is already in `$HOME/go/src` $ cd $HOME/go/src/golang.org/x/tour $ go build $ go install $ tour
-d flag for
The -d flag instructs get to download the source code needed to build the named packages, including downloading necessary dependencies, but not to build and install them.
With that being the case, manually building and installing is necessary, but it works!
And now, I can get to actually learning Go!
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!