diff --git a/doc/articles/go_command.html b/doc/articles/go_command.html index 002c034367..0fd83cb53a 100644 --- a/doc/articles/go_command.html +++ b/doc/articles/go_command.html @@ -97,13 +97,14 @@ a tool like the go command to look at an unfamiliar import path and deduce where to obtain the source code.

Second, the place to store sources in the local file system is derived -in a known way from the import path. Specifically, the first choice -is $GOPATH/src/<import-path>. If $GOPATH is -unset, the go command will fall back to storing source code alongside the -standard Go packages, in $GOROOT/src/<import-path>. +in a known way from the import path, specifically +$GOPATH/src/<import-path>. +If unset, $GOPATH defaults to a subdirectory +named go in the user's home directory. If $GOPATH is set to a list of paths, the go command tries <dir>/src/<import-path> for each of the directories in -that list.

+that list. +

Each of those trees contains, by convention, a top-level directory named "bin", for holding compiled executables, and a top-level directory @@ -137,28 +138,13 @@ to the use of a specific tool chain.

Getting started with the go command

-

Finally, a quick tour of how to use the go command, to supplement -the information in How to Write Go Code, -which you might want to read first. Assuming you want -to keep your source code separate from the Go distribution source -tree, the first step is to set $GOPATH, the one piece of global -configuration that the go command needs. The $GOPATH can be a -list of directories, but by far the most common usage should be to set it to a -single directory. In particular, you do not need a separate entry in -$GOPATH for each of your projects. One $GOPATH can -support many projects.

+

Finally, a quick tour of how to use the go command. +As mentioned above, the default $GOPATH on Unix is $HOME/go. +We'll store our programs there. +To use a different location, you can set $GOPATH; +see How to Write Go Code for details. -

Here’s an example. Let’s say we decide to keep our Go code in the directory -$HOME/mygo. We need to create that directory and set -$GOPATH accordingly.

- -
-$ mkdir $HOME/mygo
-$ export GOPATH=$HOME/mygo
-$
-
- -

Into this directory, we now add some source code. Suppose we want to use +

We first add some source code. Suppose we want to use the indexing library from the codesearch project along with a left-leaning red-black tree. We can install both with the "go get" subcommand:

@@ -169,8 +155,8 @@ $ go get github.com/petar/GoLLRB/llrb $ -

Both of these projects are now downloaded and installed into our -$GOPATH directory. The one tree now contains the two directories +

Both of these projects are now downloaded and installed into $HOME/go, +which contains the two directories src/github.com/google/codesearch/index/ and src/github.com/petar/GoLLRB/llrb/, along with the compiled packages (in pkg/) for those libraries and their dependencies.

@@ -184,6 +170,7 @@ the pattern "./..." means start in the current directory ("..."):

+$ cd $HOME/go/src
 $ go list ./...
 github.com/google/codesearch/cmd/cgrep
 github.com/google/codesearch/cmd/cindex
@@ -215,7 +202,7 @@ $
 current directory:

-$ cd $GOPATH/src/github.com/google/codesearch/regexp
+$ cd github.com/google/codesearch/regexp
 $ go list
 github.com/google/codesearch/regexp
 $ go test -v
@@ -244,9 +231,6 @@ pick such a long name, but that ability would require additional configuration
 and complexity in the tool. Typing an extra directory name or two is a small
 price to pay for the increased simplicity and power.

-

As the example shows, it’s fine to work with packages from many different -projects at once within a single $GOPATH root directory.

-

Limitations

As mentioned above, the go command is not a general-purpose build diff --git a/doc/code.html b/doc/code.html index b64bc1a142..9978b523b4 100644 --- a/doc/code.html +++ b/doc/code.html @@ -120,30 +120,43 @@ We will discuss the distinction later.

The GOPATH environment variable specifies the location of your -workspace. It is likely the only environment variable you'll need to set -when developing Go code. +workspace. It defaults to a directory named go inside your home directory, +so $HOME/go on Unix, +$home/go on Plan 9, +and %USERPROFILE%\go (usually C:\Users\YourName\go) on Windows. +If you would like to work in a different location, you will need to set +GOPATH to the path to that directory. +(Another common setup is to set GOPATH=$HOME.) +Note that GOPATH must not be the +same path as your Go installation.

-To get started, create a workspace directory and set GOPATH -accordingly. Your workspace can be located wherever you like, but we'll use -$HOME/work in this document. Note that this must not be the -same path as your Go installation. -(Another common setup is to set GOPATH=$HOME.) +The command go env GOPATH +prints the effective current GOPATH; +it prints the default location if the environment variable is unset.

-
-$ mkdir $HOME/work
-$ export GOPATH=$HOME/work
-
-

For convenience, add the workspace's bin subdirectory to your PATH:

-$ export PATH=$PATH:$GOPATH/bin
+$ export PATH=$PATH:$(go env GOPATH)/bin
+
+ +

+The scripts in the rest of this document use $GOPATH +instead of $(go env GOPATH) for brevity. +To make the scripts run as written +if you have not set GOPATH, +you can substitute $HOME/go in those commands +or else run: +

+ +
+$ export GOPATH=$(go env GOPATH)
 

diff --git a/doc/go_faq.html b/doc/go_faq.html index 884d98ba6e..3006b3d3d4 100644 --- a/doc/go_faq.html +++ b/doc/go_faq.html @@ -1094,7 +1094,7 @@ it's easy to work around this. For GitHub, try one of these solutions: