2012-02-13 23:02:28 -07:00
<!-- {
"Title": "Installing Go from source",
2012-03-04 20:31:27 -07:00
"Path": "/doc/install/source"
2012-02-13 23:02:28 -07:00
}-->
< h2 id = "introduction" > Introduction< / h2 >
2012-03-02 15:36:09 -07:00
< p >
Go is an open source project, distributed under a
2012-02-13 23:02:28 -07:00
< a href = "/LICENSE" > BSD-style license< / a > .
This document explains how to check out the sources,
build them on your own machine, and run them.
< / p >
2012-03-02 15:36:09 -07:00
< p >
Most users don't need to do this, and will instead install
from precompiled binary packages as described in
2012-03-04 20:31:27 -07:00
< a href = "/doc/install" > Getting Started< / a > ,
2012-03-02 15:36:09 -07:00
a much simpler process.
If you want to help develop what goes into those precompiled
packages, though, read on.
< / p >
2012-02-13 23:02:28 -07:00
< div class = "detail" >
< p >
2018-01-09 13:26:21 -07:00
There are two official Go compiler toolchains.
2012-02-13 23:02:28 -07:00
This document focuses on the < code > gc< / code > Go
2015-06-23 17:50:12 -06:00
compiler and tools.
2012-03-02 15:36:09 -07:00
For information on how to work on < code > gccgo< / code > , a more traditional
2012-02-13 23:02:28 -07:00
compiler using the GCC back end, see
2012-03-04 20:31:27 -07:00
< a href = "/doc/install/gccgo" > Setting up and using gccgo< / a > .
2012-02-13 23:02:28 -07:00
< / p >
< p >
2020-06-29 06:32:22 -06:00
The Go compilers support the following instruction sets:
2012-02-13 23:02:28 -07:00
< dl >
< dt >
2019-10-19 04:31:59 -06:00
< code > amd64< / code > , < code > 386< / code >
2012-02-13 23:02:28 -07:00
< / dt >
< dd >
2019-10-19 04:31:59 -06:00
The < code > x86< / code > instruction set, 64- and 32-bit.
2015-06-10 03:56:01 -06:00
< / dd >
< dt >
2019-10-19 04:31:59 -06:00
< code > arm64< / code > , < code > arm< / code >
2015-06-10 03:56:01 -06:00
< / dt >
< dd >
2019-10-19 04:31:59 -06:00
The < code > ARM< / code > instruction set, 64-bit (< code > AArch64< / code > ) and 32-bit.
2015-06-10 03:56:01 -06:00
< / dd >
2020-06-29 06:32:22 -06:00
< dt >
< code > mips64< / code > , < code > mips64le< / code > , < code > mips< / code > , < code > mipsle< / code >
< / dt >
< dd >
The < code > MIPS< / code > instruction set, big- and little-endian, 64- and 32-bit.
< / dd >
2015-06-10 03:56:01 -06:00
< dt >
2019-10-19 04:31:59 -06:00
< code > ppc64< / code > , < code > ppc64le< / code >
2015-06-10 03:56:01 -06:00
< / dt >
< dd >
2019-10-19 04:31:59 -06:00
The 64-bit PowerPC instruction set, big- and little-endian.
2012-02-13 23:02:28 -07:00
< / dd >
2016-12-01 21:12:18 -07:00
< dt >
2020-06-29 06:32:22 -06:00
< code > riscv64< / code >
2016-12-01 21:12:18 -07:00
< / dt >
< dd >
2020-06-29 06:32:22 -06:00
The 64-bit RISC-V instruction set.
2016-12-01 21:12:18 -07:00
< / dd >
2015-11-13 01:12:26 -07:00
< dt >
2020-06-29 06:32:22 -06:00
< code > s390x< / code >
2015-11-13 01:12:26 -07:00
< / dt >
< dd >
2020-06-29 06:32:22 -06:00
The IBM z/Architecture.
2015-11-13 01:12:26 -07:00
< / dd >
2016-06-19 23:33:52 -06:00
< dt >
2019-10-19 04:31:59 -06:00
< code > wasm< / code >
2016-06-19 23:33:52 -06:00
< / dt >
< dd >
2019-10-19 04:31:59 -06:00
< a href = "https://webassembly.org" > WebAssembly< / a > .
2019-08-09 03:07:39 -06:00
< / dd >
2012-02-13 23:02:28 -07:00
< / dl >
2019-10-19 04:31:59 -06:00
< / p >
< p >
The compilers can target the AIX, Android, DragonFly BSD, FreeBSD,
Illumos, Linux, macOS/iOS (Darwin), NetBSD, OpenBSD, Plan 9, Solaris,
and Windows operating systems (although not all operating systems
support all architectures).
< / p >
2012-02-13 23:02:28 -07:00
< p >
2019-10-19 04:31:59 -06:00
A list of ports which are considered "first class" is available at the
< a href = "/wiki/PortingPolicy#first-class-ports" > first class ports< / a >
wiki page.
2012-02-13 23:02:28 -07:00
< / p >
< p >
2019-10-19 04:31:59 -06:00
The full set of supported combinations is listed in the
discussion of < a href = "#environment" > environment variables< / a > below.
2012-02-13 23:02:28 -07:00
< / p >
2016-01-06 13:51:01 -07:00
< p >
See the main installation page for the < a href = "/doc/install#requirements" > overall system requirements< / a > .
The following additional constraints apply to systems that can be built only from source:
< / p >
< ul >
< li > For Linux on PowerPC 64-bit, the minimum supported kernel version is 2.6.37, meaning that
Go does not support CentOS 6 on these systems.
< / li >
< / ul >
2012-02-13 23:02:28 -07:00
< / div >
2020-03-21 06:22:14 -06:00
< h2 id = "go14" > Install Go compiler binaries for bootstrap< / h2 >
2012-02-13 23:02:28 -07:00
< p >
2018-01-09 13:26:21 -07:00
The Go toolchain is written in Go. To build it, you need a Go compiler installed.
2020-03-21 06:22:14 -06:00
The scripts that do the initial build of the tools look for a "go" command
in < code > $PATH< / code > , so as long as you have Go installed in your
system and configured in your < code > $PATH< / code > , you are ready to build Go
from source.
Or if you prefer you can set < code > $GOROOT_BOOTSTRAP< / code > to the
root of a Go installation to use to build the new Go toolchain;
< code > $GOROOT_BOOTSTRAP/bin/go< / code > should be the go command to use.< / p >
2015-02-10 18:44:50 -07:00
2019-08-04 23:46:29 -06:00
< h3 id = "bootstrapFromBinaryRelease" > Bootstrap toolchain from binary release< / h3 >
2015-02-10 18:44:50 -07:00
< p >
2018-01-09 13:26:21 -07:00
To use a binary release as a bootstrap toolchain, see
2016-10-28 12:03:21 -06:00
< a href = "/dl/" > the downloads page< / a > or use any other
packaged Go distribution.
2012-02-13 23:02:28 -07:00
< / p >
2019-08-04 23:46:29 -06:00
< h3 id = "bootstrapFromSource" > Bootstrap toolchain from source< / h3 >
2015-06-10 04:13:39 -06:00
< p >
2018-01-09 13:26:21 -07:00
To build a bootstrap toolchain from source, use
2016-10-28 12:03:21 -06:00
either the git branch < code > release-branch.go1.4< / code > or
2017-11-26 09:30:39 -07:00
< a href = "https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz" > go1.4-bootstrap-20171003.tar.gz< / a > ,
2016-10-28 12:03:21 -06:00
which contains the Go 1.4 source code plus accumulated fixes
to keep the tools running on newer operating systems.
2018-01-09 13:26:21 -07:00
(Go 1.4 was the last distribution in which the toolchain was written in C.)
2017-01-24 10:56:57 -07:00
After unpacking the Go 1.4 source, < code > cd< / code > to
2017-09-08 15:38:10 -06:00
the < code > src< / code > subdirectory, set < code > CGO_ENABLED=0< / code > in
the environment, and run < code > make.bash< / code > (or,
2017-01-24 10:56:57 -07:00
on Windows, < code > make.bat< / code > ).
2016-10-28 12:03:21 -06:00
< / p >
2019-08-04 23:46:29 -06:00
< p >
Once the Go 1.4 source has been unpacked into your GOROOT_BOOTSTRAP directory,
you must keep this git clone instance checked out to branch
< code > release-branch.go1.4< / code > . Specifically, do not attempt to reuse
this git clone in the later step named "Fetch the repository." The go1.4
bootstrap toolchain < b > must be able< / b > to properly traverse the go1.4 sources
that it assumes are present under this repository root.
< / p >
< h3 id = "bootstrapFromCrosscompiledSource" > Bootstrap toolchain from cross-compiled source< / h3 >
2016-10-28 12:03:21 -06:00
< p >
2018-01-09 13:26:21 -07:00
To cross-compile a bootstrap toolchain from source, which is
2016-10-28 12:03:21 -06:00
necessary on systems Go 1.4 did not target (for
example, < code > linux/ppc64le< / code > ), install Go on a different system
and run < a href = "/src/bootstrap.bash" > bootstrap.bash< / a > .
2015-06-10 04:13:39 -06:00
< / p >
< p >
When run as (for example)
< / p >
< pre >
$ GOOS=linux GOARCH=ppc64 ./bootstrap.bash
< / pre >
< p >
< code > bootstrap.bash< / code > cross-compiles a toolchain for that < code > GOOS/GOARCH< / code >
combination, leaving the resulting tree in < code > ../../go-${GOOS}-${GOARCH}-bootstrap< / code > .
That tree can be copied to a machine of the given target type
and used as < code > GOROOT_BOOTSTRAP< / code > to bootstrap a local build.
< / p >
2019-08-04 23:46:29 -06:00
< h3 id = "bootstrapFromGccgo" > Bootstrap toolchain using gccgo< / h3 >
2015-06-10 04:13:39 -06:00
< p >
2016-10-28 12:03:21 -06:00
To use gccgo as the bootstrap toolchain, you need to arrange
for < code > $GOROOT_BOOTSTRAP/bin/go< / code > to be the go tool that comes
as part of gccgo 5. For example on Ubuntu Vivid:
2015-06-10 04:13:39 -06:00
< / p >
< pre >
$ sudo apt-get install gccgo-5
$ sudo update-alternatives --set go /usr/bin/go-5
$ GOROOT_BOOTSTRAP=/usr ./make.bash
< / pre >
2014-12-11 19:53:29 -07:00
< h2 id = "git" > Install Git, if needed< / h2 >
2012-02-13 23:02:28 -07:00
< p >
2014-12-11 19:53:29 -07:00
To perform the next step you must have Git installed. (Check that you
have a < code > git< / code > command before proceeding.)
2012-02-13 23:02:28 -07:00
< / p >
< p >
2014-12-11 19:53:29 -07:00
If you do not have a working Git installation,
2012-04-13 21:27:11 -06:00
follow the instructions on the
2018-06-13 01:06:04 -06:00
< a href = "https://git-scm.com/downloads" > Git downloads< / a > page.
2012-02-13 23:02:28 -07:00
< / p >
2016-01-26 15:56:08 -07:00
< h2 id = "ccompiler" > (Optional) Install a C compiler< / h2 >
< p >
To build a Go installation
with < code > < a href = "/cmd/cgo" > cgo< / a > < / code > support, which permits Go
programs to import C libraries, a C compiler such as < code > gcc< / code >
or < code > clang< / code > must be installed first. Do this using whatever
installation method is standard on the system.
< / p >
< p >
To build without < code > cgo< / code > , set the environment variable
< code > CGO_ENABLED=0< / code > before running < code > all.bash< / code > or
< code > make.bash< / code > .
< / p >
2012-02-13 23:02:28 -07:00
< h2 id = "fetch" > Fetch the repository< / h2 >
2019-06-13 17:56:37 -06:00
< p > Change to the directory where you intend to install Go, and make sure
the < code > goroot< / code > directory does not exist. Then clone the repository
and check out the latest release tag (< code class = "versionTag" > go1.12< / code > ,
for example):< / p >
2012-02-13 23:02:28 -07:00
< pre >
2019-06-13 17:56:37 -06:00
$ git clone https://go.googlesource.com/go goroot
$ cd goroot
2016-04-13 20:12:11 -06:00
$ git checkout < span class = "versionTag" > < i > < tag> < / i > < / span >
2012-02-13 23:02:28 -07:00
< / pre >
2016-04-13 20:12:11 -06:00
< p class = "whereTag" >
Where < code > < tag> < / code > is the version string of the release.
< / p >
2019-06-13 17:56:37 -06:00
< p > Go will be installed in the directory where it is checked out. For example,
if Go is checked out in < code > $HOME/goroot< / code > , executables will be installed
in < code > $HOME/goroot/bin< / code > . The directory may have any name, but note
that if Go is checked out in < code > $HOME/go< / code > , it will conflict with
the default location of < code > $GOPATH< / code > .
See < a href = "#gopath" > < code > GOPATH< / code > < / a > below.< / p >
2019-12-07 08:52:10 -07:00
< p >
2019-08-04 23:46:29 -06:00
Reminder: If you opted to also compile the bootstrap binaries from source (in an
earlier section), you still need to < code > git clone< / code > again at this point
(to checkout the latest < code > < tag> < / code > ), because you must keep your
go1.4 repository distinct.
2019-12-07 08:52:10 -07:00
< / p >
2019-08-04 23:46:29 -06:00
2014-12-11 19:53:29 -07:00
< h2 id = "head" > (Optional) Switch to the master branch< / h2 >
2012-09-26 12:39:31 -06:00
< p > If you intend to modify the go source code, and
< a href = "/doc/contribute.html" > contribute your changes< / a >
to the project, then move your repository
2014-12-11 19:53:29 -07:00
off the release branch, and onto the master (development) branch.
2012-09-26 12:39:31 -06:00
Otherwise, skip this step.< / p >
< pre >
2014-12-11 19:53:29 -07:00
$ git checkout master
2012-09-26 12:39:31 -06:00
< / pre >
2012-02-13 23:02:28 -07:00
< h2 id = "install" > Install Go< / h2 >
< p >
To build the Go distribution, run
< / p >
< pre >
2015-02-25 11:57:45 -07:00
$ cd src
2012-02-13 23:02:28 -07:00
$ ./all.bash
< / pre >
< p >
(To build under Windows use < code > all.bat< / code > .)
< / p >
< p >
If all goes well, it will finish by printing output like:
< / p >
< pre >
ALL TESTS PASSED
---
Installed Go for linux/amd64 in /home/you/go.
Installed commands in /home/you/go/bin.
*** You need to add /home/you/go/bin to your $PATH. ***
< / pre >
< p >
where the details on the last few lines reflect the operating system,
architecture, and root directory used during the install.
< / p >
< div class = "detail" >
< p >
For more information about ways to control the build, see the discussion of
< a href = "#environment" > environment variables< / a > below.
2013-12-15 19:03:12 -07:00
< code > all.bash< / code > (or < code > all.bat< / code > ) runs important tests for Go,
which can take more time than simply building Go. If you do not want to run
the test suite use < code > make.bash< / code > (or < code > make.bat< / code > )
instead.
2012-02-13 23:02:28 -07:00
< / p >
< / div >
< h2 id = "testing" > Testing your installation< / h2 >
< p >
Check that Go is installed correctly by building a simple program.
< / p >
< p >
Create a file named < code > hello.go< / code > and put the following program in it:
< / p >
< pre >
package main
import "fmt"
func main() {
2018-04-10 21:22:59 -06:00
fmt.Printf("hello, world\n")
2012-02-13 23:02:28 -07:00
}
< / pre >
< p >
Then run it with the < code > go< / code > tool:
< / p >
< pre >
$ go run hello.go
hello, world
< / pre >
< p >
If you see the "hello, world" message then Go is installed correctly.
< / p >
2012-06-12 18:33:02 -06:00
< h2 id = "gopath" > Set up your work environment< / h2 >
< p >
2013-11-20 13:55:29 -07:00
You're almost done.
You just need to do a little more setup.
2012-06-12 18:33:02 -06:00
< / p >
2012-02-13 23:02:28 -07:00
2013-11-20 13:55:29 -07:00
< p >
< a href = "/doc/code.html" class = "download" id = "start" >
< span class = "big" > How to Write Go Code< / span >
< span class = "desc" > Learn how to set up and use the Go tools< / span >
< / a >
< / p >
< p >
2016-12-01 18:45:26 -07:00
The < a href = "/doc/code.html" > How to Write Go Code< / a > document
2013-11-20 13:55:29 -07:00
provides < b > essential setup instructions< / b > for using the Go tools.
< / p >
2013-09-24 22:10:49 -06:00
< h2 id = "tools" > Install additional tools< / h2 >
< p >
2013-09-24 22:27:23 -06:00
The source code for several Go tools (including < a href = "/cmd/godoc/" > godoc< / a > )
2014-11-09 15:15:57 -07:00
is kept in < a href = "https://golang.org/x/tools" > the go.tools repository< / a > .
2019-02-12 21:45:45 -07:00
To install one of the tools (< code > godoc< / code > in this case):
2013-09-24 22:10:49 -06:00
< / p >
< pre >
2014-11-09 15:15:57 -07:00
$ go get golang.org/x/tools/cmd/godoc
2013-09-24 22:10:49 -06:00
< / pre >
< p >
2016-12-01 18:45:26 -07:00
To install these tools, the < code > go< / code > < code > get< / code > command requires
2014-12-11 19:53:29 -07:00
that < a href = "#git" > Git< / a > be installed locally.
2013-09-24 22:10:49 -06:00
< / p >
< p >
You must also have a workspace (< code > GOPATH< / code > ) set up;
see < a href = "/doc/code.html" > How to Write Go Code< / a > for the details.
< / p >
2012-02-13 23:02:28 -07:00
< h2 id = "community" > Community resources< / h2 >
< p >
2012-03-02 15:36:09 -07:00
The usual community resources such as
2018-06-13 01:06:04 -06:00
< code > #go-nuts< / code > on the < a href = "https://freenode.net/" > Freenode< / a > IRC server
2012-03-02 15:36:09 -07:00
and the
2014-07-24 18:28:39 -06:00
< a href = "//groups.google.com/group/golang-nuts" > Go Nuts< / a >
2012-03-02 15:36:09 -07:00
mailing list have active developers that can help you with problems
with your installation or your development work.
For those who wish to keep up to date,
2014-07-24 18:28:39 -06:00
there is another mailing list, < a href = "//groups.google.com/group/golang-checkins" > golang-checkins< / a > ,
2012-03-02 15:36:09 -07:00
that receives a message summarizing each checkin to the Go repository.
2012-02-13 23:02:28 -07:00
< / p >
< p >
2014-12-11 19:53:29 -07:00
Bugs can be reported using the < a href = "//golang.org/issue/new" > Go issue tracker< / a > .
2012-02-13 23:02:28 -07:00
< / p >
< h2 id = "releases" > Keeping up with releases< / h2 >
< p >
2014-12-11 19:53:29 -07:00
New releases are announced on the
2014-07-24 18:28:39 -06:00
< a href = "//groups.google.com/group/golang-announce" > golang-announce< / a >
2012-02-13 23:02:28 -07:00
mailing list.
2014-12-11 19:53:29 -07:00
Each announcement mentions the latest release tag, for instance,
2017-08-24 12:52:35 -06:00
< code class = "versionTag" > go1.9< / code > .
2012-02-13 23:02:28 -07:00
< / p >
< p >
To update an existing tree to the latest release, you can run:
< / p >
< pre >
$ cd go/src
2014-12-11 19:53:29 -07:00
$ git fetch
2016-04-13 20:12:11 -06:00
$ git checkout < span class = "versionTag" > < i > < tag> < / i > < / psan >
2012-02-13 23:02:28 -07:00
$ ./all.bash
< / pre >
2016-04-13 20:12:11 -06:00
< p class = "whereTag" >
2014-12-11 19:53:29 -07:00
Where < code > < tag> < / code > is the version string of the release.
2016-04-13 20:12:11 -06:00
< / p >
2014-12-11 19:53:29 -07:00
2012-02-13 23:02:28 -07:00
< h2 id = "environment" > Optional environment variables< / h2 >
< p >
The Go compilation environment can be customized by environment variables.
2012-03-02 15:36:09 -07:00
< i > None is required by the build< / i > , but you may wish to set some
2012-02-13 23:02:28 -07:00
to override the defaults.
< / p >
2013-06-09 09:15:39 -06:00
< ul >
< li > < code > $GOROOT< / code >
2012-03-05 21:16:02 -07:00
< p >
2016-11-30 12:56:58 -07:00
The root of the Go tree, often < code > $HOME/go1.X< / code > .
2012-03-05 21:16:02 -07:00
Its value is built into the tree when it is compiled, and
defaults to the parent of the directory where < code > all.bash< / code > was run.
There is no need to set this unless you want to switch between multiple
local copies of the repository.
< / p >
2018-01-30 09:55:27 -07:00
< / li >
2012-03-05 21:16:02 -07:00
2013-06-09 09:15:39 -06:00
< li > < code > $GOROOT_FINAL< / code >
2012-03-05 21:16:02 -07:00
< p >
The value assumed by installed binaries and scripts when
< code > $GOROOT< / code > is not set explicitly.
It defaults to the value of < code > $GOROOT< / code > .
If you want to build the Go tree in one location
2016-12-01 18:45:26 -07:00
but move it elsewhere after the build, set
2012-03-05 21:16:02 -07:00
< code > $GOROOT_FINAL< / code > to the eventual location.
< / p >
2018-01-30 09:55:27 -07:00
< / li >
2012-03-05 21:16:02 -07:00
2019-06-13 17:56:37 -06:00
< li id = "gopath" > < code > $GOPATH< / code >
< p >
The directory where Go projects outside the Go distribution are typically
checked out. For example, < code > golang.org/x/tools< / code > might be checked out
to < code > $GOPATH/src/golang.org/x/tools< / code > . Executables outside the
Go distribution are installed in < code > $GOPATH/bin< / code > (or
< code > $GOBIN< / code > , if set). Modules are downloaded and cached in
< code > $GOPATH/pkg/mod< / code > .
< / p >
< p > The default location of < code > $GOPATH< / code > is < code > $HOME/go< / code > ,
and it's not usually necessary to set < code > GOPATH< / code > explicitly. However,
if you have checked out the Go distribution to < code > $HOME/go< / code > ,
you must set < code > GOPATH< / code > to another location to avoid conflicts.
< / p >
< / li >
< li > < code > $GOBIN< / code >
< p >
The directory where executables outside the Go distribution are installed
using the < a href = "/cmd/go" > go command< / a > . For example,
< code > go get golang.org/x/tools/cmd/godoc< / code > downloads, builds, and
installs < code > $GOBIN/godoc< / code > . By default, < code > $GOBIN< / code > is
< code > $GOPATH/bin< / code > (or < code > $HOME/go/bin< / code > if < code > GOPATH< / code >
is not set). After installing, you will want to add this directory to
your < code > $PATH< / code > so you can use installed tools.
< / p >
< p >
Note that the Go distribution's executables are installed in
< code > $GOROOT/bin< / code > (for executables invoked by people) or
< code > $GOTOOLDIR< / code > (for executables invoked by the go command;
defaults to < code > $GOROOT/pkg/$GOOS_GOARCH< / code > ) instead of
< code > $GOBIN< / code > .
< / p >
< / li >
2013-06-09 09:15:39 -06:00
< li > < code > $GOOS< / code > and < code > $GOARCH< / code >
2012-03-05 21:16:02 -07:00
< p >
The name of the target operating system and compilation architecture.
These default to the values of < code > $GOHOSTOS< / code > and
< code > $GOHOSTARCH< / code > respectively (described below).
2018-01-30 09:55:27 -07:00
< / li >
2012-03-05 21:16:02 -07:00
< p >
Choices for < code > $GOOS< / code > are
2020-05-18 18:55:50 -06:00
< code > android< / code > , < code > darwin< / code > (macOS/iOS),
2019-08-09 03:07:39 -06:00
< code > dragonfly< / code > , < code > freebsd< / code > , < code > illumos< / code > , < code > js< / code > ,
2015-06-10 03:56:01 -06:00
< code > linux< / code > , < code > netbsd< / code > , < code > openbsd< / code > ,
2014-03-25 21:21:28 -06:00
< code > plan9< / code > , < code > solaris< / code > and < code > windows< / code > .
2019-08-09 03:07:39 -06:00
< / p >
< p >
2012-03-05 21:16:02 -07:00
Choices for < code > $GOARCH< / code > are
< code > amd64< / code > (64-bit x86, the most mature port),
2015-06-10 03:56:01 -06:00
< code > 386< / code > (32-bit x86), < code > arm< / code > (32-bit ARM), < code > arm64< / code > (64-bit ARM),
2015-11-13 01:12:26 -07:00
< code > ppc64le< / code > (PowerPC 64-bit, little-endian), < code > ppc64< / code > (PowerPC 64-bit, big-endian),
2017-08-23 05:45:27 -06:00
< code > mips64le< / code > (MIPS 64-bit, little-endian), < code > mips64< / code > (MIPS 64-bit, big-endian),
2019-08-09 03:07:39 -06:00
< code > mipsle< / code > (MIPS 32-bit, little-endian), < code > mips< / code > (MIPS 32-bit, big-endian),
< code > s390x< / code > (IBM System z 64-bit, big-endian), and
< code > wasm< / code > (WebAssembly 32-bit).
< / p >
< p >
2012-03-05 21:16:02 -07:00
The valid combinations of < code > $GOOS< / code > and < code > $GOARCH< / code > are:
< table cellpadding = "0" >
< tr >
2013-06-09 09:15:39 -06:00
< th width = "50" > < / th > < th align = "left" width = "100" > < code > $GOOS< / code > < / th > < th align = "left" width = "100" > < code > $GOARCH< / code > < / th >
2012-03-05 21:16:02 -07:00
< / tr >
< tr >
2019-08-09 03:07:39 -06:00
< td > < / td > < td > < code > aix< / code > < / td > < td > < code > ppc64< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > android< / code > < / td > < td > < code > 386< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > android< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
2016-02-24 16:06:03 -07:00
< td > < / td > < td > < code > android< / code > < / td > < td > < code > arm< / code > < / td >
< / tr >
< tr >
2019-08-09 03:07:39 -06:00
< td > < / td > < td > < code > android< / code > < / td > < td > < code > arm64< / code > < / td >
< / tr >
< tr >
2012-03-05 21:16:02 -07:00
< td > < / td > < td > < code > darwin< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
2015-06-10 03:56:01 -06:00
< td > < / td > < td > < code > darwin< / code > < / td > < td > < code > arm64< / code > < / td >
2014-03-25 23:06:18 -06:00
< / tr >
< tr >
< td > < / td > < td > < code > dragonfly< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
2012-03-05 21:16:02 -07:00
< td > < / td > < td > < code > freebsd< / code > < / td > < td > < code > 386< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > freebsd< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
2013-06-09 09:15:39 -06:00
< td > < / td > < td > < code > freebsd< / code > < / td > < td > < code > arm< / code > < / td >
< / tr >
< tr >
2019-08-09 03:07:39 -06:00
< td > < / td > < td > < code > illumos< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > js< / code > < / td > < td > < code > wasm< / code > < / td >
< / tr >
< tr >
2012-03-05 21:16:02 -07:00
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > 386< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > arm< / code > < / td >
< / tr >
< tr >
2015-06-10 03:56:01 -06:00
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > arm64< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > ppc64< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > ppc64le< / code > < / td >
< / tr >
< tr >
2016-12-01 21:12:18 -07:00
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > mips< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > mipsle< / code > < / td >
< / tr >
< tr >
2015-11-13 01:12:26 -07:00
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > mips64< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > mips64le< / code > < / td >
< / tr >
< tr >
2017-08-23 05:45:27 -06:00
< td > < / td > < td > < code > linux< / code > < / td > < td > < code > s390x< / code > < / td >
< / tr >
< tr >
2012-03-05 21:16:02 -07:00
< td > < / td > < td > < code > netbsd< / code > < / td > < td > < code > 386< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > netbsd< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
2013-06-09 09:15:39 -06:00
< td > < / td > < td > < code > netbsd< / code > < / td > < td > < code > arm< / code > < / td >
< / tr >
< tr >
2012-03-05 21:16:02 -07:00
< td > < / td > < td > < code > openbsd< / code > < / td > < td > < code > 386< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > openbsd< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
2015-06-10 03:56:01 -06:00
< td > < / td > < td > < code > openbsd< / code > < / td > < td > < code > arm< / code > < / td >
< / tr >
< tr >
2019-08-09 03:07:39 -06:00
< td > < / td > < td > < code > openbsd< / code > < / td > < td > < code > arm64< / code > < / td >
< / tr >
< tr >
2012-03-05 21:16:02 -07:00
< td > < / td > < td > < code > plan9< / code > < / td > < td > < code > 386< / code > < / td >
< / tr >
< tr >
2013-06-09 09:15:39 -06:00
< td > < / td > < td > < code > plan9< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
2019-08-09 03:07:39 -06:00
< td > < / td > < td > < code > plan9< / code > < / td > < td > < code > arm< / code > < / td >
< / tr >
< tr >
2014-03-25 21:21:28 -06:00
< td > < / td > < td > < code > solaris< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< tr >
2012-03-05 21:16:02 -07:00
< td > < / td > < td > < code > windows< / code > < / td > < td > < code > 386< / code > < / td >
< / tr >
< tr >
< td > < / td > < td > < code > windows< / code > < / td > < td > < code > amd64< / code > < / td >
< / tr >
< / table >
2015-07-22 05:00:32 -06:00
< br >
2012-03-05 21:16:02 -07:00
2013-06-09 09:15:39 -06:00
< li > < code > $GOHOSTOS< / code > and < code > $GOHOSTARCH< / code >
2012-03-05 21:16:02 -07:00
< p >
The name of the host operating system and compilation architecture.
These default to the local system's operating system and
architecture.
< / p >
2018-01-30 09:55:27 -07:00
< / li >
2012-03-05 21:16:02 -07:00
< p >
Valid choices are the same as for < code > $GOOS< / code > and
< code > $GOARCH< / code > , listed above.
The specified values must be compatible with the local system.
2016-12-01 18:45:26 -07:00
For example, you should not set < code > $GOHOSTARCH< / code > to
2012-03-05 21:16:02 -07:00
< code > arm< / code > on an x86 system.
< / p >
2013-06-09 09:15:39 -06:00
< li > < code > $GO386< / code > (for < code > 386< / code > only, default is auto-detected
2014-06-04 17:53:37 -06:00
if built on either < code > 386< / code > or < code > amd64< / code > , < code > 387< / code > otherwise)
2013-06-09 09:15:39 -06:00
< p >
2015-06-23 17:50:12 -06:00
This controls the code generated by gc to use either the 387 floating-point unit
2013-06-09 09:15:39 -06:00
(set to < code > 387< / code > ) or SSE2 instructions (set to < code > sse2< / code > ) for
floating point computations.
< / p >
< ul >
2018-01-30 09:55:27 -07:00
< li > < code > GO386=387< / code > : use x87 for floating point operations; should support all x86 chips (Pentium MMX or later).< / li >
< li > < code > GO386=sse2< / code > : use SSE2 for floating point operations; has better performance than 387, but only available on Pentium 4/Opteron/Athlon 64 or later.< / li >
2013-06-09 09:15:39 -06:00
< / ul >
2018-01-30 09:55:27 -07:00
< / li >
2013-06-09 09:15:39 -06:00
< li > < code > $GOARM< / code > (for < code > arm< / code > only; default is auto-detected if building
on the target processor, 6 if not)
< p >
This sets the ARM floating point co-processor architecture version the run-time
should target. If you are compiling on the target system, its value will be auto-detected.
< / p >
< ul >
2018-01-30 09:55:27 -07:00
< li > < code > GOARM=5< / code > : use software floating point; when CPU doesn't have VFP co-processor< / li >
< li > < code > GOARM=6< / code > : use VFPv1 only; default if cross compiling; usually ARM11 or better cores (VFPv2 or better is also supported)< / li >
< li > < code > GOARM=7< / code > : use VFPv3; usually Cortex-A cores< / li >
2013-06-09 09:15:39 -06:00
< / ul >
2012-03-05 21:16:02 -07:00
< p >
2013-06-09 09:15:39 -06:00
If in doubt, leave this variable unset, and adjust it if required
when you first run the Go executable.
2014-07-24 18:28:39 -06:00
The < a href = "//golang.org/wiki/GoArm" > GoARM< / a > page
on the < a href = "//golang.org/wiki" > Go community wiki< / a >
2013-06-09 09:15:39 -06:00
contains further details regarding Go's ARM support.
2012-03-05 21:16:02 -07:00
< / p >
2018-01-30 09:55:27 -07:00
< / li >
2018-08-29 05:56:37 -06:00
< li > < code > $GOMIPS< / code > (for < code > mips< / code > and < code > mipsle< / code > only) < br > < code > $GOMIPS64< / code > (for < code > mips64< / code > and < code > mips64le< / code > only)
2018-01-30 09:55:27 -07:00
< p >
2018-08-29 05:56:37 -06:00
These variables set whether to use floating point instructions. Set to "< code > hardfloat< / code > " to use floating point instructions; this is the default. Set to "< code > softfloat< / code > " to use soft floating point.
2018-01-30 09:55:27 -07:00
< / p >
< / li >
2012-03-05 21:16:02 -07:00
2019-01-11 12:16:28 -07:00
< li > < code > $GOPPC64< / code > (for < code > ppc64< / code > and < code > ppc64le< / code > only)
< p >
This variable sets the processor level (i.e. Instruction Set Architecture version)
for which the compiler will target. The default is < code > power8< / code > .
< / p >
< ul >
< li > < code > GOPPC64=power8< / code > : generate ISA v2.07 instructions< / li >
< li > < code > GOPPC64=power9< / code > : generate ISA v3.00 instructions< / li >
< / ul >
< / li >
2019-03-23 07:18:19 -06:00
< li > < code > $GOWASM< / code > (for < code > wasm< / code > only)
< p >
This variable is a comma separated list of < a href = "https://github.com/WebAssembly/proposals" > experimental WebAssembly features< / a > that the compiled WebAssembly binary is allowed to use.
The default is to use no experimental features.
< / p >
< ul >
2019-03-24 05:14:27 -06:00
< li > < code > GOWASM=satconv< / code > : generate < a href = "https://github.com/WebAssembly/nontrapping-float-to-int-conversions/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md" > saturating (non-trapping) float-to-int conversions< / a > < / li >
2019-03-23 08:25:42 -06:00
< li > < code > GOWASM=signext< / code > : generate < a href = "https://github.com/WebAssembly/sign-extension-ops/blob/master/proposals/sign-extension-ops/Overview.md" > sign-extension operators< / a > < / li >
2019-03-23 07:18:19 -06:00
< / ul >
< / li >
2013-06-09 09:15:39 -06:00
< / ul >
2012-02-13 23:02:28 -07:00
< p >
Note that < code > $GOARCH< / code > and < code > $GOOS< / code > identify the
< em > target< / em > environment, not the environment you are running on.
In effect, you are always cross-compiling.
By architecture, we mean the kind of binaries
that the target environment can run:
an x86-64 system running a 32-bit-only operating system
must set < code > GOARCH< / code > to < code > 386< / code > ,
not < code > amd64< / code > .
< / p >
< p >
If you choose to override the defaults,
set these variables in your shell profile (< code > $HOME/.bashrc< / code > ,
2016-12-01 18:45:26 -07:00
< code > $HOME/.profile< / code > , or equivalent). The settings might look
2012-02-13 23:02:28 -07:00
something like this:
< / p >
< pre >
export GOARCH=amd64
export GOOS=linux
< / pre >
2012-03-02 15:36:09 -07:00
< p >
although, to reiterate, none of these variables needs to be set to build,
install, and develop the Go tree.
< / p >