Go Language Introductory Tour (i): Environmental construction-windows

Source: Internet
Author: User
Tags install go

A Golang small white study notes, hope to learn together with you, write a bad place, please correct me, thank you! ~

In the Windows Install Go Language development environment is relatively simple, go officially provides MSI and zip two format of the installation package, we can choose 32-bit or 64-bit according to their operating system, download the corresponding installation package.

Installation

1. msi installation package

Using the MSI installation package, you only need to follow the installation interface prompts to install, the installation process will be based on the installation directory we choose to configure the environment variables.

2. zip installation package

Unzip the downloaded ZIP installation package to a directory (C:\go is recommended)

Configuring Environment variables

1. Goroot

Goroot points to the install directory of Go.

If you install with an MSI package, the installation tool has already configured the GOROOT environment variable by default and configures the Goroot/bin directory to the PATH environment variable.

If we use the ZIP installation package, we need to configure the zip unzipped directory into the goroot variable, which is configured as follows

Control Panel > Systems > Advanced system Settings > Advanced > Environment variables

The above steps allow you to open the Windows Environment Variables Configuration window, create a new goroot variable in the user variable (available to the current user) or a system variable (available to all system users), the variable value is the Go installation directory, and add%goroot/bin% to the end of the PATH environment variable.

After the configuration is complete, run the Go command in the cmd command, and the result is as follows: configured successfully

> GoGo is a tool for managing Go source code.       Usage:go command [arguments]the commands are:build compile packages and dependencies clean Remove object files Doc show documentation for package or symbol env print Go environmen T information bug start a bug report fix run Go tool fix on packages FMT run  GOFMT on package sources generate generate Go files by processing source get download and install Packages and dependencies install compile and install packages and Dependencies list List Packag         Es run compile and run Go Program test test Packages Tool run specified Go tool Version print Go version vet run Go tool vet on Packagesuse ' Go help [command] ' for more inform ation about a command. Additional help Topics:c calling between Go and C bUildmode description of build modes filetype file types Gopath gopath environment variable        Environment environment Variables Importpath Import path Syntax packages description of package lists  Testflag Description of testing flags TestFunc description of testing FunctionsUse "Go help [topic]" for More information on that topic.

2. Gopath

The Gopath environment is configured with the work area of the go language, and is configured in the same way as goroot, but cannot point to the same directory as goroot, i.e. not to the Go Language installation directory, in go1.1~ Go1.7 all require Gopath, after Go1.8, if not configured, under the Windows operating system, the Gopath default value%userprofile%.

According to the Go language specification, Gopath points to the directory must have three directories: SRC,BIN,PKG,SRC store Our development of the Go Project source code, that is, where we write codes, bin storage compiled after the executable file, pkg storage compiled after the generated file.

The general Gopath directory is as follows

$GOPATH  bin/      main.exe  pkg/      windows_amd64            lib.a  src/          main.go          lib              lib.go

First Go Language Program

Create a new Main.go file in the src directory of Gopath, with the following code

package mainimport "fmt"func main(){  fmt.Println("Hello World")}

Run

src> go run main.goHello World
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.