Go install and use

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Download the installation package

Download from http://code.google.com/p/go/downloads/list website Choose a response based on your operating system the appropriate version of the edition, I chose theGo1.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-click My Computer--Properties--Advanced system settings-environment variables




Set Goroot


Add the bin path to the path directory



Open terminal Run Go Version command, if it appears as shown, the installation is successful



Four setting up the 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, equivalent to our working directory, in a Unix-like environment such as setting: 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, 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 store 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 choose: liteidex19.windows.7z 14.3 MB 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"
)
FuncMain (){
    Fmt. Println ("HelloWorld")
}
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.