golang installation
Enter the official website -> https://golang.org/
Choose their own system download
Environment Variables
- Adding Environment Variables
Mac to as terminal zsh example, the following command input
>> vi ~/.zshrc
In the last append the following codes
# /Users/quaint/study/golang-study 为你的golang 工作空间, 该空间下应该包含3个文件夹 src pkg bin
# root 为go安装目录 path 为go工作空间
export GOROOT=/usr/local/go
export GOPATH=/Users/quaint/study/golang-study
export PATH=$PATH:$GOROOT
export PATH=$PATH:$GOPATH:$GOPATH/bin
- Check the Environment Variables
Restart terminal, enter the following command
>> go version
go version go1.14 darwin/amd64
>> go evn
查看 GOPATH 和 GOROOT 是否指向你的工作空间
vscode plug-in installation
chinese Chinese Simplified (Microsoft)
go (Microsoft)
go tools AnSo
Press the Mac platform Command+Shift+P
, this time VS Code interface will pop up an input box, enter the following command.
Go:Install/Update Tools
Select All, click OK or press Enter
go.toolsGopath setting is not set. Using GOPATH /Users/quaint/study/golang-study
Installing 17 tools at /Users/quaint/study/golang-study/bin in module mode.
gocode
gopkgs
go-outline
go-symbols
guru
gorename
gotests
gomodifytags
impl
fillstruct
goplay
godoctor
dlv
gocode-gomod
godef
goreturns
golint
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED
Installing github.com/mdempsky/gocode FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED
Installing github.com/acroca/go-symbols FAILED
Installing github.com/ramya-rao-a/go-outline FAILED
Installing golang.org/x/tools/cmd/guru FAILED
Installing github.com/acroca/go-symbols FAILED
Installing golang.org/x/tools/cmd/gorename FAILED
Installing golang.org/x/tools/cmd/guru FAILED
You will find that many have failed to install. You can use git tools for installation.
The first step: now own GOPATH
the src
created directory golang.org/x
directory
Step Two: In 终端中
cd 到
under GOPATH / src / golang.org / x` directory
The third step: execute git clone https://github.com/golang/tools.git tools
command
Step Four: Execute git clone https://github.com/golang/lint.git
command
Step Five: Press Ctrl/Command+Shift+P
executed again Go:Install/Update Tools
command, in the pop-up window and click OK whole election, this time the installation will be SUCCESSED
up.
Write helloword
package main
import "fmt"
func main(){
fmt.Println("hello world!");
}
Compile helloword
# 编译当前工作目录的go文件
>> go build
>> go build fileName
>> go build -o outName.exe
# 成功之后项目会多一个hello word 文件,执行他
>> ./helloword
hello word!
Acknowledgments
Thanks Levin week's blog detailed the Go language tutorial.