Go Environment Common variable record

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

The Go development environment is dependent on some operating system environment variables, so you'd better set them up when you install go. If you are using Windows, you do not have to manually set up, Go will be installed by default in the directory C:/go. Here are some of the most important environment variables:

    • $GOROOT indicates where Go is installed on your PC, the value is generally $HOME/go, and of course you can install it somewhere else.
    • $GOARCH represents the processor architecture of the target machine, and its value can be 386, AMD64, or arm.
    • $GOOS represents the operating system of the target machine, and its value can be Darwin, FreeBSD, Linux, or Windows.
    • $GOBIN indicates where the compiler and linker are installed, by default it is $GOROOT/bin, if you are using Go 1.0.3 and later, in general you can set its value to null and Go will use the default values mentioned earlier.

The target machine is the machine on which you intend to run your Go application.

The Go compiler supports cross-compiling, meaning that you can build applications running on a single machine that run on different operating systems and processor architectures, meaning that the machine that writes the source code can have a completely different feature (operating system and processor architecture) than the target machine.

To differentiate between the local machine and the target machine, you can use the $GOHOSTOS and $GOHOSTARCH to set the parameters of the target machine, which are used only when cross-compiling, and if you do not display the settings, their values will be the same as the local machine ($GOOS and $GOARCH).

    • $GOPATH   defaults to the same values as $GOROOT, but you have to change to a different path starting with the Go 1.1 release. It can contain multiple paths that contain the Go language source files, package files, and executable files, which must contain three specified directories: SRC, pkg, and bin, which are used to store source files, package files, and executables, respectively.
    • $GOARM   is designed for ARM architecture-based processors with a value of 5 or 6, which defaults to 6.
    • $GOMAXPROCS   Sets the number of processors and the number of cores that the application can use, as described in section 14th. 1.3.
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.