Linux下安装go开发环境

下载GO二进制包

打开go中文社区的go二进制包下载页面,下载对应环境的安装包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#找个地儿放go源码包
mkdir /opt/go/{golang,gopath}
tar xf go1.10.3.linux-amd64.tar.gz
cp -r go/* /opt/go/golang

#配置goroot和gopath
#说明:goroot环境变量是指定go原生工具包所在位置
# gopath环境变量是指定go第三方包和自定义包所在位置
# 我这里对gopath进行了拆分,将第三方和自己写的代码分开管理
vim ~/.bashrc
export GOROOT=/opt/go/golang
export GOPATH=/opt/go/gopath:/home/user/go
GOOBIN=/opt/go/gopath/bin:/home/user/go/bin
export PATH=$GOROOT/bin:$GOOBIN:$PATH

安装go工具包

1
2
3
4
5
6
7
8
9
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols
go get -u -v golang.org/x/tools/cmd/guru

其中golang.org中的包没有梯子的情况下无法直接go get,可以从github上下载安装

1
2
3
mkdir /opt/go/gopath/golang.org/x
cd /opt/go/gopath/golang.org/x
git clone https://github.com/golang/text.git

安装go编辑器

vscode版本

  • rhel系列安装

    1
    2
    3
    4
    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
    sudo yum repolist
    sudo yum install code
  • debian系列安装

    1
    2
    3
    4
    5
    curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
    sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
    sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
    sudo apt-get update
    sudo apt-get install code

打开vscode,在扩展中搜索go并安装即可

0%