Golang环境搭建

Golang环境配置

1. 下载安装包

下载相应的安装包,对应自己的CPU型号,我以x86架构的为例

wget https://studygolang.com/dl/golang/go1.14.6.linux-amd64.tar.gz

2. 解压安装包

tar -zxvf go1.14.6.linux-amd64.tar.gz -C /usr/local/lib

3. 设置环境变量

vim .zshrc
# add golang config
export GOROOT="/usr/local/lib/go"
export GOPATH="/root/codes/go"
export GOBIN="/roots/codes/go/bin"
export PATH="/usr/local/lib/go/bin:$PATH"
export GO111MODULE=auto
export GOPROXY=https://goproxy.io
:wq
source .zshrc

4. 验证是否安装成功

go version
go version go1.14.6 linux/arm
go env
GO111MODULE="auto"
GOARCH="arm"
GOBIN="/roots/codes/go/bin"
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/roots/codes/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/lib/go/pkg/tool/linux_arm"
GCCGO="gccgo"
GOARM="6"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build628959611=/tmp/go-build -gno-record-gcc-switches"

5. 编码测试

mkdir -p $GOPATH/src/test
cd $GOPATH/src/test && vim main.go
package main
import(
"fmt"
)
func main(){
fmt.Println("Hello World")
}

在vim中会出现以下问题

FileNotFoundError: [Errno 2] No such file or directory: '/root/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/bin/gopls': '/root/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/bin/gopls'

这说明缺少默认go的一些二进制文件,在.vimrc去执行

:GoInstallBinaries

和之前装Vim plugins的时候一样,需要等待所有的依赖二进制文件全部安装完毕。

vim-go: installing finished!
posted @ 2021-02-10 16:06  ttlv  阅读(186)  评论(0编辑  收藏  举报