Go install and use

Source: Internet
Author: User
Download the installation package

Download the appropriate version of the response based on your operating system from the Http://code.google.com/p/go/downloads/list URL, I chose Go1.1.2.windows-386.zip 32.7 MB
Note: You can also select the. msi file to install, so that it will be installed automatically in the C:/go directory (here is not recommended to download MSI version)
Two decompression
Unzip the downloaded file, put it in a directory, I put the go in the D:\go directory




Three setting environment variables
$GOROOT point to the root directory after the Golang installation, if you choose. msi installation, the default is C:/go under Windows, and the system environment variables are automatically written to the Setup program during installation.
Processor Architecture $GOARCH Target platform (compiled target platform) (386, AMD64, ARM)
Operating system $GOOS target platform (compiled target platform) (Darwin, FreeBSD, Linux, Windows)
$GOBIN point to the Bin directory under the root directory after installation, that is, the default is C:/go/bin under the $goroot/bin,windows platform, which is automatically added to the path variable by the Setup program during the installation process
For us we only need to configure Goroot and Gobin (if you download an MSI installation, it will be automatically written to the environment variable, without our configuration) right----Properties---Advanced system settings--environment variables




Set Goroot


Add the bin path to the path directory



Open the terminal to run the Go version command, if it appears as shown in the following figure, the installation is successful



Construction of the four editing environment

1. First you need to set the Gopath directory
The GO command relies on an important environment variable: $GOPATH Note: A. This is not the Go install directory, the equivalent of our working directory, in a Unix-like environment such as settings: Export Gopath=/home/apple/mygo B. Gopath allow multiple directories, when there are multiple directories, note the delimiter,  Multiple directories when Windows is a semicolon, the Linux system is a colon, when there are multiple Gopath, the default is to put the contents of go get in the first directory C. The $GOPATH directory convention has three subdirectories: SRC holds source code (e.g.. Go. C. h, etc.)
The files generated by the PKG after compilation (for example:. a)
Bin compiled executable (for convenience, this directory can be added to the $PATH variable, if there are multiple gopath, then use ${gopath//://bin:}/bin to add all Bin directory)


We create a new directory in the D disk Goproject as our Gopath directory, and a folder in the directory src, used to store our source files.
Add the Goptah to the environment variable:


2. Download Liteide http://code.google.com/p/golangide/downloads/list
Select the appropriate version, where we select: liteidex19.windows.7z 14.3 MB to run after decompression
Select the system environment we want to run:


Set the system environment variables in liteide to the values we set above


To set the Gopath in Liteide:


Select the file system, then create a new Hello directory under SRC, and then create a new Main.go file under the directory:

To write code in MAIN.GO:

Package Main


Import (

    "FMT"
)


Func Main () {

    Fmt. Println ("Hello World")
}
Open Terminal input: Go install hello (note: Need to run as Administrator)

At this point you will find that a new bin directory is automatically created in goproject with the exe file we just generated.

Note: You can also directly click on the liteide in the BR run program, but this will be generated in the SRC directory exe program, this does not conform to the Go Project directory Management policy, so I recommend this.

We can use Liteide as an editor, and it's a good idea to have the go command in the terminal when you compile and run the program. Let's Run the program here:

We can also put d:goproject\bin into the PATH environment variable, so that you can run the program directly.
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.