From: Jay Conrod Go will install to a directory named Change to the directory where you intend to install Go, and make sure
+the cgo
, set the environment variable
Fetch the repository
-go
.
-Change to the directory that will be its parent
-and make sure the go
directory does not exist.
-Then clone the repository and check out the latest release tag
-(go1.9
, for example):goroot
directory does not exist. Then clone the repository
+and check out the latest release tag (go1.12
,
+for example):
-$ git clone https://go.googlesource.com/go
-$ cd go
+$ git clone https://go.googlesource.com/go goroot
+$ cd goroot
$ git checkout <tag>
@@ -234,6 +233,13 @@ $ git checkout <tag>
Where <tag>
is the version string of the release.
Go will be installed in the directory where it is checked out. For example,
+if Go is checked out in $HOME/goroot
, executables will be installed
+in $HOME/goroot/bin
. The directory may have any name, but note
+that if Go is checked out in $HOME/go
, it will conflict with
+the default location of $GOPATH
.
+See GOPATH
below.
If you intend to modify the go source code, and @@ -441,6 +447,43 @@ but move it elsewhere after the build, set
+$GOPATH
+
+The directory where Go projects outside the Go distribution are typically
+checked out. For example, golang.org/x/tools
might be checked out
+to $GOPATH/src/golang.org/x/tools
. Executables outside the
+Go distribution are installed in $GOPATH/bin
(or
+$GOBIN
, if set). Modules are downloaded and cached in
+$GOPATH/pkg/mod
.
+
The default location of $GOPATH
is $HOME/go
,
+and it's not usually necessary to set GOPATH
explicitly. However,
+if you have checked out the Go distribution to $HOME/go
,
+you must set GOPATH
to another location to avoid conflicts.
+
$GOBIN
+
+The directory where executables outside the Go distribution are installed
+using the go command. For example,
+go get golang.org/x/tools/cmd/godoc
downloads, builds, and
+installs $GOBIN/godoc
. By default, $GOBIN
is
+$GOPATH/bin
(or $HOME/go/bin
if GOPATH
+is not set). After installing, you will want to add this directory to
+your $PATH
so you can use installed tools.
+
+Note that the Go distribution's executables are installed in
+$GOROOT/bin
(for executables invoked by people) or
+$GOTOOLDIR
(for executables invoked by the go command;
+defaults to $GOROOT/pkg/$GOOS_GOARCH
) instead of
+$GOBIN
.
+
$GOOS
and $GOARCH
The name of the target operating system and compilation architecture.
@@ -577,17 +620,6 @@ For example, you should not set $GOHOSTARCH
to
arm
on an x86 system.
$GOBIN
-
-The location where Go binaries will be installed.
-The default is $GOROOT/bin
.
-After installing, you will want to arrange to add this
-directory to your $PATH
, so you can use the tools.
-If $GOBIN
is set, the go command
-installs all commands there.
-
$GO386
(for 386
only, default is auto-detected
if built on either 386
or amd64
, 387
otherwise)
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index df6b9e3e5d..d2ce578564 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -674,6 +674,15 @@ // // Install compiles and installs the packages named by the import paths. // +// Executables are installed in the directory named by the GOBIN environment +// variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH +// environment variable is not set. Executables in $GOROOT +// are installed in $GOROOT/bin or $GOTOOLDIR instead of $GOBIN. +// +// When module-aware mode is disabled, other packages are installed in the +// directory $GOPATH/pkg/$GOOS_$GOARCH. When module-aware mode is enabled, +// other packages are built and cached but not installed. +// // The -i flag installs the dependencies of the named packages as well. // // For more about the build flags, see 'go help build'. diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index 9c03f0818d..ed5a149da3 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -404,6 +404,15 @@ var CmdInstall = &base.Command{ Long: ` Install compiles and installs the packages named by the import paths. +Executables are installed in the directory named by the GOBIN environment +variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH +environment variable is not set. Executables in $GOROOT +are installed in $GOROOT/bin or $GOTOOLDIR instead of $GOBIN. + +When module-aware mode is disabled, other packages are installed in the +directory $GOPATH/pkg/$GOOS_$GOARCH. When module-aware mode is enabled, +other packages are built and cached but not installed. + The -i flag installs the dependencies of the named packages as well. For more about the build flags, see 'go help build'.