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