Go Basic installation and environment variable description

Source: Internet
Author: User
Tags windows x86
This is a creation in Article, where the information may have evolved or changed.

Go installation and configuration in the official has been very detailed instructions, installation instructions please refer to the official link: https://golang.org/doc/install

To facilitate development, the installation of the development environment needs to be aware of the settings of three environment variables:

1,$GOROOT: Go installation directory, configuration will no longer change;

2,$PATH: Need to add the Go Bin directory to the system $path in order to facilitate the use of the relevant commands of go, configuration will not be changed;

3,$GOPATH: Go project in the local development environment of the project root path (so that project compilation, go build, go install), different projects at the time of compiling the environment variable can be different

The GO environment variable is also described in the official documentation for details, please refer to the link: https://golang.org/doc/install/source

$GOROOT the root of the Go tree, often $HOME/go1. X. Its value are built into the tree when it's compiled, and defaults to the parent of the directory where All.bash was RU  N. There is no need to set this unless you want to switch between multiple local copies of the repository. $GOROOT _final The value assumed by installed binaries and scripts when $GOROOT are not set explicitly. It defaults to the value of $GOROOT. If you want to build the Go tree on one location but move it elsewhere after the build, set $GOROOT _final to the eventual  Location. $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 is Darwin (Mac OS X 10.8 and above and IOS), Dragonfly, FreeBSD, Linux, NetBSD, OpenBSD, Plan9, Solaris and Windows. Choices for $GOARCH is 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 MIP S64 (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: $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 Lin UX MIPS Linux mipsle linux MIPS64 linux mips64le NetBSD 386 NetBSD AMD64 Net BSD arm OpenBSD 386 OpenBSD AMD64 OpenBSD arm plan9 386 plan9 AMD64 Solaris am D64 Windows 386 Windows AMD64 $GOHOSTOS and $GOHOSTARCH the name of the host operating system and Compilat Ion architecture. These default to the LOCAl system ' s operating system and architecture. Valid choices is the same as for $GOOS and $GOARCH, listed above. The specified values must is compatible with the local system.     For example, you should the not set $GOHOSTARCH the to arm in an x86 system. $GOBIN the location where Go binaries would be installed. The default is $GOROOT/bin. After installing, you'll 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. $GO 386 (for 386 only, default was auto-detected if built on either 386 or AMD64, 387 otherwise) this controls the code G Enerated by GC to use either the 387-floating-point unit (set to 387) or SSE2 instructions (set-to-SSE2) for floating poin        T computations. Go386=387:use x87 for floating point operations;    Should support all x86 chips (Pentium MMX or later). Go386=sse2:use SSE2 for floating point operations; Have better performance than 387, but only available on PentiuM 4/opteron/athlon or later. $GOARM (for ARM only; default was auto-detected if building on the target processor, 6 if not) this sets the arm floatin G Point co-processor Architecture version the Run-time should target.        If you is compiling on the target system, its value would be auto-detected. Goarm=5:use software floating point; When CPU doesn ' t has VFP co-processor goarm=6:use VFPv1 only; Default if cross compiling; Usually ARM11 or better cores (VFPV2 or better is also supported) Goarm=7:use VFPv3; Usually cortex-a cores if in doubt, leave this variable unset, and adjust it If required when you first run the Go exec Utable. The Goarm page on the go community Wiki contains further details regarding Go's ARM support.

The $goos and $goarch in the environment variables are more practical two variables that can be used in cross-compilation on different platforms, just set these two variables before go build, which is one of the advantages of the Go language: You can compile executables that run across platforms. It feels more efficient and lightweight than QT, although the resulting executable is a little larger, but within an acceptable range.

For example, to compile an executable file for Windows x86 under the Linux AMD64 architecture, you can use the following commands:

CGO_ENABLED=0 GOOS=windows GOARCH=386 go build hello.go

Unfortunately, cross-compilation does not support CGO, so you need to set the environment variable $cgo_enabled to 0, so that after execution, a hello.exe executable file of the Windows x86 schema is generated in the current directory:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.