安装指南
安装
获取可安装的版本:
brew search go | egrep '^go$|^go@.*$'
安装最新版本:
brew install go
安装指定版本:
brew install go@1.14
brew install go@1.16
获取已安装的版本:
brew list | grep go
# Inter
ll -d /usr/local/Cellar/go*
# M1
ll -d /opt/homebrew/Cellar/go*
获取当前使用的版本:
go version
切换版本:
brew unlink go
brew link go@1.14
创建工作目录:
mkdir -p /Users/${USER}/Desktop/Project/golang
环境变量
设置环境变量:
go env -w GOOS="darwin"
go env -w GOARCH="amd64"
go env -w GOPATH="/Users/${USER}/Desktop/Project/golang"
go env -w GOBIN="$(go env GOPATH)/bin"
go env -w GO111MODULE="auto"
go env -w GOPROXY="https://goproxy.io,https://proxy.golang.org,https://goproxy.cn,direct"
echo "" >> ~/.zshrc
echo "export GOPATH='/Users/${USER}/Desktop/Project/golang'" >> ~/.zshrc
echo 'export PATH="${PATH}:${GOPATH}/bin"' >> ~/.zshrc
go env -w GOOS="darwin"
go env -w GOARCH="arm64"
go env -w GOPATH="/Users/${USER}/Desktop/Project/golang"
go env -w GOBIN="$(go env GOPATH)/bin"
go env -w GO111MODULE="auto"
go env -w GOPROXY="https://goproxy.io,https://proxy.golang.org,https://goproxy.cn,direct"
echo "" >> ~/.zshrc
echo "export GOPATH='/Users/${USER}/Desktop/Project/golang'" >> ~/.zshrc
echo 'export PATH="${PATH}:${GOPATH}/bin"' >> ~/.zshrc
go env -w GOOS="linux"
go env -w GOARCH="amd64"
go env -w GOPATH="/opt/golang"
go env -w GOBIN="$(go env GOPATH)/bin"
go env -w GO111MODULE="auto"
go env -w GOPROXY="https://goproxy.io,https://proxy.golang.org,https://goproxy.cn,direct"
echo "" >> ~/.bashrc
echo "export GOPATH='/opt/golang'" >> ~/.bashrc
echo 'export PATH="${PATH}:${GOPATH}/bin"' >> ~/.bashrc
echo '' >> ~/.ssh/config
echo 'Host e.coding.net' >> ~/.ssh/config
echo ' Port 22' >> ~/.ssh/config
echo '' >> ~/.gitconfig
echo '[url "https://pt60y7hineu6:c3bccede2849bd974993b68ff55e23e13e2ca80e@e.coding.net/bitdesk/nodehub"]' >> ~/.gitconfig
echo ' insteadOf = https://e.coding.net/bitdesk/nodehub' >> ~/.gitconfig
go env -w GONOPROXY="e.coding.net"
go env -w GONOSUMDB="e.coding.net"
go env -w GOPRIVATE="e.coding.net"
获取环境变量:
# 获取所有变量
go env
# 获取指定变量
go env GOOS
还原环境变量:
go env -u GOOS
模块管理
初始化项目:
# 可执行
go mod init
# 库
go mod init github.com/go-agumon/table
根据go.mod
文件处理依赖关系(查缺补漏)
go mod tidy
将依赖包复制到项目下的vendor
目录
go mod vendor
获取依赖关系
go list -m all