Set the environment variable GOARCH to the value amd64. This instructs the go command to generate files for amd64. Other valid values for GOARCH include 386, arm, arm64, and others.

Answer from fuz on Stack Overflow
Top answer
1 of 2
14

Set the environment variable GOARCH to the value amd64. This instructs the go command to generate files for amd64. Other valid values for GOARCH include 386, arm, arm64, and others.

2 of 2
2

F.Y.I.

The Go compilers support the following instruction sets:

  • amd64, 386
    • The x86 instruction set, 64- and 32-bit.
  • arm64, arm
    • The ARM instruction set, 64-bit (AArch64) and 32-bit.
  • mips64, mips64le, mips, mipsle
    • The MIPS instruction set, big- and little-endian, 64- and 32-bit.
  • ppc64, ppc64le
    • The 64-bit PowerPC instruction set, big- and little-endian.
  • riscv64
    • The 64-bit RISC-V instruction set.
  • s390x
    • The IBM z/Architecture.
  • wasm
    • WebAssembly.

(from: Introduction | Installing Go from source | Doc @ golang.org)

Also, you can go tool dist list to check the available architectures to build in your machine.

Copy$ go tool dist list
aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
(* snip *)
    

To build a static binary for macOS (Intel/ARM64) would be as below. In this manner, I suppose GOOS="darwin" GOARCH="arm64" combination will be for M1 architecture.

CopyMyVar="foo"

CGO_ENABLED=0 \
        GOOS="darwin" \
        GOARCH="amd64" \
        GOARM="" \
        go build \
        -ldflags="-s -w -extldflags \"-static\" -X 'main.myVar=${MyVar}'" \
        -o="/path/to/export/bin/myApp" \
        "/path/to/main.go"

To compile for Linux on ARM v6, such as RaspberryPi Zero W, the combination would be as below.

Copy$ CGO_ENABLED=0 GOOS="linux" GOARCH="arm" GOARM="6" go build .
🌐
Google Groups
groups.google.com › g › golang-nuts › c › jRX5uwX3I9Q
unsupported GOOS/GOARCH pair darwin/x86_64 on mac installed from package
> $ go run hello.go > cmd/go: unsupported GOOS/GOARCH pair darwin/x86_64 > GOARCH="x86_64" Set GOARCH in the environment to amd64, not x86_64. Or don't bother to set it at all.
Discussions

unsupported GOOS/GOARCH pair darwin/x86_64
Go version go version go1.22.2 darwin/amd64 Output of go env in your module/workspace: go env GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/Users/sergehulne/Library/C... More on github.com
🌐 github.com
3
April 18, 2024
go - All possible GOOS value? - Stack Overflow
Choices for $GOARCH are amd64 (64-bit x86, the most mature port), 386 (32-bit x86), arm (32-bit ARM), arm64 (64-bit ARM), ppc64le (PowerPC 64-bit, little-endian), ppc64 (PowerPC 64-bit, big-endian), mips64le (MIPS 64-bit, little-endian), and mips64 (MIPS 64-bit, big-endian). More on stackoverflow.com
🌐 stackoverflow.com
gobootstrap: Doesn't respect `GOARCH=amd64`, `CC='arch -x86_64 clang'`, or `CC='clang -arch x86_64'` on Apple silicon
gobootstrap: Doesn't respect GOARCH=amd64, CC='arch -x86_64 clang', or CC='clang -arch x86_64' on Apple silicon#58368 More on github.com
🌐 github.com
1
February 6, 2023
nm
We made a mistake because AWS docs are terrible. nm More on github.com
🌐 github.com
4
August 20, 2022
🌐
Go
go.dev › doc › install › source
Installing Go from source - The Go Programming Language
Choices for $GOARCH are amd64 (64-bit x86, the most mature port), 386 (32-bit x86), arm (32-bit ARM), arm64 (64-bit ARM), ppc64le (PowerPC 64-bit, little-endian), ppc64 (PowerPC 64-bit, big-endian), mips64le (MIPS 64-bit, little-endian), mips64 (MIPS 64-bit, big-endian), mipsle (MIPS 32-bit, ...
🌐
GitHub
gist.github.com › asukakenji › f15ba7e588ac42795f421b48b8aede63
Go (Golang) GOOS and GOARCH · GitHub
# command-line-arguments loadinternal: ... for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ... The amd64p32 GOARCH, which is related to the nacl GOOS, was also dropped since go version ...
🌐
Hectorcorrea
hectorcorrea.com › blog › 2025-11-11 › go-build-tool-machine-architecture
Go executables and machine architecture - Hector Correa
November 11, 2025 - $ go env GOOS GOARCH darwin amd64 $ GOOS=linux go build -o marcli_linux $ file marcli_linux ELF 64-bit LSB executable, x86-64 ...
🌐
Opensource.com
opensource.com › article › 21 › 1 › go-cross-compiling
Cross-compiling made easy with Golang | Opensource.com
January 14, 2021 - I checked the Golang docs and ... GOOS refers to the operating system (Linux, Windows, BSD, etc.), while GOARCH refers to the architecture to build for....
🌐
Xebia
xebia.com › home › blog › go cross platform compilation
Go Cross Platform Compilation | Xebia
April 30, 2025 - $ GOOS=darwin GOARCH=amd64 go build -o helloworld-mac helloworld.go $ file helloworld-mac helloworld: Mach-O 64-bit executable x86_64 $ GOOS=linux GOARCH=amd64 go build -o helloworld-linux helloworld.go $ file helloworld-linux helloworld-linux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped $ GOOS=windows GOARCH=amd64 go build -o helloworld-windows.exe helloworld.go $ file helloworld-windows.exe helloworld-windows.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows ·
Find elsewhere
🌐
GitHub
github.com › golang › go › issues › 66883
unsupported GOOS/GOARCH pair darwin/x86_64 · Issue #66883 · golang/go
April 18, 2024 - Go version go version go1.22.2 darwin/amd64 Output of go env in your module/workspace: go env GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/Users/sergehulne/Library/C...
Author   golang
🌐
https://unsafe.sh
buaq.net › go-1925.html
Go (Golang) GOOS and GOARCH - 不安全
April 2, 2019 - #!/bin/bash # Reference: # https://github.com/golang/go/blob/master/src/go/build/syslist.go os_archs=( darwin/386 darwin/amd64 dragonfly/amd64 freebsd/386 freebsd/amd64 freebsd/arm linux/386 linux/amd64 linux/arm linux/arm64 linux/ppc64 linux/ppc64le linux/mips linux/mipsle linux/mips64 linux/mips64le linux/s390x nacl/386 nacl/amd64p32 nacl/arm netbsd/386 netbsd/amd64 netbsd/arm openbsd/386 openbsd/amd64 openbsd/arm plan9/386 plan9/amd64 plan9/arm solaris/amd64 windows/386 windows/amd64 ) os_archs_32=() os_archs_64=() for os_arch in "${os_archs[@]}" do goos=${os_arch%/*} goarch=${os_arch#*/} G
🌐
Marcelocantos
marcelocantos.com › posts › goos-goarch-survey
GOOS/GOARCH combos on macOS | Marcelo Cantos
18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64 i386 MacBookPro10,1 Darwin $ go version go version go1.11.4 darwin/amd64 · $ cat hello.go package main import ( "fmt" ) func main() { fmt.Println("Hello, playground") } $ GOOS=android GOARCH=386 go build # play/hello /usr/local/Cellar/go/1.11.4/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1 ld: unknown option: -z clang: error: linker command failed with exit code 1 (use -v to see invocation) $ GOOS=android GOARCH=amd64 go build # play/hello /usr/local/Cellar/
🌐
Go Packages
pkg.go.dev › internal › goarch
goarch package - internal/goarch - Go Packages
Int64Align is the required alignment for a 64-bit integer (4 on 32-bit systems, 8 on 64-bit). ... MinFrameSize is the size of the system-reserved words at the bottom of a frame (just above the architectural stack pointer). It is zero on x86 and PtrSize on most non-x86 (LR-based) systems.
Top answer
1 of 3
102

Note that those values are defined in:

  • src/internal/syslist/syslist.go, and
  • doc/install/source#environment.

With Go 1.5 (Q3 2015), GOARCH will become much more complete.
See commit 1eebb91 by Minux Ma (minux)

go/build: reserve GOARCH values for all common architectures

Whenever we introduce a new GOARCH, older Go releases won't recognize them and this causes trouble for both our users and us (we need to add unnecessary build tags).

Go 1.5 has introduced three new GOARCHes so far: arm64 ppc64 ppc64le, we can take the time to introduce GOARCHes for all common architectures that Go might support in the future to avoid the problem.

Copyconst goosList = "android darwin dragonfly freebsd linux nacl \ 
  netbsd openbsd plan9 solaris windows "

const goarchList = "386 amd64 amd64p32 arm arm64 ppc64 ppc64le \
   mips mipsle mips64 mips64le mips64p32 mips64p32le \ # (new)
   ppc s390 s390x sparc sparc64 " # (new)

The list is still being review in Change 9644, with comments like:

I wouldn't bother with Itanium. It's basically a dead architecture.
Plus, it's so hard to write a compiler for it that I really can't see it happening except as a labor of love, and nobody loves the Itanium.

The official documentation now (GO 1.5+ Q3 2015) reflects that completed list.


Update 2018: as documented in Giorgos Oikonomou's answer, Go 1.7 (Q1 2016) has introduced the
go tool dist list command.
See commit c3ecded: it fixes issue 12270 opened in Q3 2015:

To easier write tooling for cross compiling it would be good to programmatically get the possible combinations of GOOS and GOARCH.

This was implemented in CL 19837

cmd/dist: introduce list subcommand to list all supported platforms

You can list in plain text, or in json:

Copy> go tool dist list -json
[
        {
                "GOOS": "android",
                "GOARCH": "386",
                "CgoSupported": true
        },
        ...
]

As Mark Bates tweeted:

Bonus: Column output properly formatted for display:

Copygo tool dist list | column -c 75 | column -t
2 of 3
49

I think you're looking for this list of possible GOOS and GOARCH combinations, in this section:

http://golang.org/doc/install/source#environment

$GOOS and $GOARCH The name of the target operating system and compilation architecture. These default to the values of $GOHOSTOS and $GOHOSTARCH respectively (described below).

Choices for $GOOS are darwin (Mac OS X 10.8 and above and iOS), dragonfly, freebsd, linux, netbsd, openbsd, plan9, solaris and windows. Choices for $GOARCH are amd64 (64-bit x86, the most mature port), 386 (32-bit x86), arm (32-bit ARM), arm64 (64-bit ARM), ppc64le (PowerPC 64-bit, little-endian), ppc64 (PowerPC 64-bit, big-endian), mips64le (MIPS 64-bit, little-endian), and mips64 (MIPS 64-bit, big-endian). mipsle (MIPS 32-bit, little-endian), and mips (MIPS 32-bit, big-endian).

The valid combinations of $GOOS and $GOARCH are:

Copy$GOOS $GOARCH
android   arm
darwin    386
darwin    amd64
darwin    arm
darwin    arm64
dragonfly amd64
freebsd   386
freebsd   amd64
freebsd   arm
linux     386
linux     amd64
linux     arm
linux     arm64
linux     ppc64
linux     ppc64le
linux     mips
linux     mipsle
linux     mips64
linux     mips64le
netbsd    386
netbsd    amd64
netbsd    arm
openbsd   386
openbsd   amd64
openbsd   arm
plan9     386
plan9     amd64
solaris   amd64
windows   386
windows   amd64
🌐
Carnegie Mellon University
cs.cmu.edu › afs › cs.cmu.edu › academic › class › 15440-f11 › go › doc › install.html
Installing Go
Choices for $GOOS are linux, freebsd, darwin (Mac OS X 10.5 or 10.6), and windows (Windows, an incomplete port). Choices for $GOARCH are amd64 (64-bit x86, the most mature port), 386 (32-bit x86), and arm (32-bit ARM, an incomplete port).
🌐
Go
go.dev › wiki › GoArm
Go Wiki: Go on ARM - The Go Programming Language
Any Go program that you can compile for x86/x86_64 should work on Arm. Besides Linux and Darwin, Go is also experimentally supported on FreeBSD, OpenBSD and NetBSD. Go supports the following ARM architectural families. Starting from Go 1.1, the appropriate GOARM value will be chosen if you ...
🌐
GitHub
github.com › golang › go › issues › 58368
gobootstrap: Doesn't respect `GOARCH=amd64`, `CC='arch -x86_64 clang'`, or `CC='clang -arch x86_64'` on Apple silicon · Issue #58368 · golang/go
February 6, 2023 - Environment Go 1.19.5 (latest stable) amd64 macOS 13.2 Apple silicon Tried arch -x86_64 ./make.bash env CC='clang -arch x86_64' ./make.bash env GOARCH=amd64 ./make.bash What did you expect to see? Build for amd64 What did you see instead...
Author   golang
🌐
DigitalOcean
digitalocean.com › community › tutorials › building-go-applications-for-different-operating-systems-and-architectures
Building Go Applications for Different Operating Systems and Architectures | DigitalOcean
October 9, 2019 - Outputapp.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows · You can also set one, or both environment variables at build time. Run the following: GOOS=linux GOARCH=ppc64 go build · Your · app executable will now be replaced by a file for a different architecture.
🌐
GitHub
github.com › golang › go › issues › 54565
nm · Issue #54565 · golang/go
August 20, 2022 - We made a mistake because AWS docs are terrible. nm
Author   golang
🌐
GitHub
yellowduck.be › posts › cross-compile
Cross compiling Go apps - YellowDuck.be
August 12, 2018 - If we want to compile for a 64-bit Linux system, we would prepend the correct $GOOS and $GOARCH environment variables with the go build command: ... main: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
🌐
OneUptime
oneuptime.com › home › blog › how to cross-compile go applications on ubuntu
How to Cross-Compile Go Applications on Ubuntu
March 2, 2026 - # Compile for Linux ARM 64-bit (AWS Graviton, Raspberry Pi 4 in 64-bit mode) GOOS=linux GOARCH=arm64 go build -o myapp-linux-arm64 . # Compile for Linux ARM 32-bit (older Raspberry Pi) GOOS=linux GOARCH=arm GOARM=7 go build -o myapp-linux-armv7 . # Compile for Linux 32-bit x86 GOOS=linux GOARCH=386 go build -o myapp-linux-386 .