001 Go Language Mac system development environment construction

Source: Internet
Author: User

The Go language is a fast, static type of development language. Its main features include automatic garbage collection, concurrent programming, reflection, and so on.

Website

https://golang.org/

Download

Open https://golang.org/dl/ to view installation files and source code for Windows, Linux, MacOS systems. Click Apple macOS to download the corresponding installation file.

Image

Double-click go1.9.2.darwin-amd64.pkg the download to follow the prompts step-by-step installation. Open terminal to run after installation go version , display results

go version go1.9.2 darwin/amd64

Set working directory Gopath

Open the. BASHRC

$ vi ~/.bashrc

Add the following code:

export GOPATH="$HOME/go"export PATH="$PATH:$GOPATH/bin"

After adding the code, press ESC, enter: Wq, save the corresponding changes, run source ~/.bashrc , you can make the configuration take effect.

Open terminal to view Gopath,

$ $GOPATH# 运行结果-bash: /Users/fujinliang/go: is a directory

HelloWorld

Create a HelloWorld project directory and file

$ cd $GOPATH# bin存放编译后的可执行文件 pkg存放编译后的包文件 src存放项目源文件$ mkdir {src,bin,pkg}$ cd src$ mkdir -p fujinliang.top/go-study$ cd fujinliang.top/go-study$ mkdir 001-helloworld$ cd 001-helloworld$ vi helloworld.go

The Helloworld.go code is as follows:

package mainimport "fmt"func main() {    fmt.Println("Hello, 世界")}

Run Helloworld.go

$ go run helloworld.go# 运行结果Hello, 世界

Go common commands

# 查看go的版本信息$ go versiongo version go1.9.2 darwin/amd64# 用于编译我们指定的源码文件或代码包以及它们的依赖包$ go build helloworld.go$ ./helloworldHello, 世界# 编译并运行 go 文件$ go run helloworld.goHello, 世界

Run the Go Code online

https://play.golang.org/

Follow the public number


Follow the public number
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.