Centos下使用epel源安装:
yum install golang
Centos/Linux下源码安装golang:
wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
tar -C /usr/local -xzf go*linux-amd64.tar.gz
mkdir $HOME/go
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> ~/.bashrc
echo 'export GO111MODULE=auto' >> ~/.bashrc
source $HOME/.bashrc
安装go get工具:
yum install mercurial git bzr subversion
Windows下安装:
https://dl.google.com/go/go1.11.2.windows-amd64.zip
设置环境变量:
setx GOOS windows
setx GOARCH amd64
setx GOROOT "D:\Program Files\go"
setx GOBIN "%GOROOT%\bin"
setx GO111MODULE auto
setx PATH %PATH%;"D:\Program Files\go\bin"
交叉编译:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
减小编译生成文件大小:
go build -ldflags "-s -w"
感谢,一点不啰嗦,还很管用!
请教一下
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
stat main.go: no such file or directory
这个是为什么了?
交叉编译的作用是?