go-ubuntu安装golang
go-ubuntu安装golang
前篇
- Ubuntu 安装最新版 (1.12) Golang 并使用 go mod - https://my.oschina.net/bfbd/blog/3044784
安装 golang
- 删除旧 go 版本 - 1 
 2
 3
 4- $ whereis go // 查找 go 在哪 
 /usr/bin/go
 $ rm -fr /usr/bin/go // 删除
- 下载并解压到 - /opt目录下. 去官网: https://golang.org/dl/ 找到需要的包, 这里用 1.14.4 版本- 1 
 2
 3
 4
 5
 6- $ wget https://golang.org/dl/go1.14.4.linux-amd64.tar.gz 
 $ tar -zxvf go1.14.4.linux-amd64.tar.gz -C /opt
 // 查看是否安装 ok
 $ /opt/go/bin/go version
 go version go1.14.4 linux/amd64
- 建立软连接 - 1 - $ ln -s /opt/go/bin/* /usr/bin/ 
- 修改环境变量, go 的工作空间为 - ~/go-workspace- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27- // 创建 go 工作空间 
 $ mkdir -p $HOME/go-workspace/src
 $ mkdir -p $HOME/go-workspace/pkg
 $ mkdir -p $HOME/go-workspace/bin
 // 添加环境变量
 $ vi ~/.bashrc
 export GOROOT=/opt/go
 export GOPROXY=https://goproxy.io
 export GOPATH=$HOME/go-workspace
 export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
 // 使之生效
 $ source ~/.bashrc
 // 最后查看一下
 $ go env
 root@NAS-Wilker:~/go-workspace# go env
 GO111MODULE=""
 GOBIN=""
 GOCACHE="/root/.cache/go-build"
 GOPROXY="https://goproxy.io"
 GOENV="/root/.config/go/env"
 GOHOSTARCH="amd64"
 GOOS="linux"
 GOPATH="/root/go-workspace"
 GOROOT="/opt/go"
- done. 然后就可以把 go 代码工程丢到 - ~/go-workspace/src目录下跑了
安装 protobuf
- Ubuntu 安装 protobuf - https://www.jianshu.com/p/ea1cdd33f2b3
- 命令 - 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19- $ apt-get install autoconf automake libtool curl make g++ unzip 
 $ git clone https://github.com/google/protobuf.git
 $ cd protobuf
 $ git submodule update --init --recursive
 $ ./autogen.sh
 $ ./configure
 $ make
 $ make check
 $ sudo make install
 $ sudo ldconfig # refresh shared library cache.