安装Go 1.11,关联 golang
Binary Distributions
Official binary distributions are available at https://golang.org/dl/.
After downloading a binary release, visit https://golang.org/doc/install or load doc/install.html in your web browser for installation instructions.
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
- Add /usr/local/go/bin to the PATH environment variable.
adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:1
export PATH=$PATH:/usr/local/go/bin
-
设置环境变量:
在 /etc/profile 添加:
1 2 3 4 5 6 7
export GOROOT=/usr/local/go export GOBIN=$GOROOT/bin export GOPKG=$GOROOT/pkg/tool/linux_amd64 export GOARCH=amd64 export GOOS=linux export GOPATH=$HOME/workspace/go export PATH=$PATH:$GOBIN:$GOPKG:${GOPATH//://bin:}/bin
windows
下载msi(如,go1.11.5.windows-amd64.msi)直接安装,执行路径都自动添加到path配置,默认安装在 c:\go
Mac OS
1 | brew install golang |
Installing Go from source
https://golang.org/doc/install/source
检查是否安装成功
-
Create your workspace directory,
%USERPROFILE%\go
.
(If you’d like to use a different directory, you will need to set the GOPATH environment variable.) -
make the directory src/hello inside your workspace
- in that directory create a file named
hello.go
1 2 3 4 5 6 7
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
- 编译
1 2
C:\> cd %USERPROFILE%\go\src\hello C:\Users\Gopher\go\src\hello> go build
- 运行
C:\Users\your-name\go\src\hello> hello