最近用回了ubuntu ,所以打算安装golang学习当下比较火热的这个语言
本来打算使用 sudo apt-get install golang的 安装后发现 是1.2.1不是最新版
所以上网上搜了一下。在git上找到一个叫做 gvm的东东,是golang版本管理器
地址:https://github.com/moovweb/gvm
1 第一步 如果你用的是Ubuntu 需要提前安装一些库
执行:
sudo apt-get install curl git mercurial make binutils bison gcc build-essential
2 如果你用的是bash shell ,默认你没有按过别的shell ,一般都用的bash shell
执行:
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
3 终端显示如下 表示安装好了
1 Cloning from https://github.com/moovweb/gvm.git to /home/c3t/.gvm 2 Created profile for existing install of Go at "/usr/lib/go" 3 Installed GVM v1.0.22 4 5 Please restart your terminal session or to get started right away run 6 `source /home/c3t/.gvm/scripts/gvm`
5上面 第5行告诉你重启终端 执行
source /home/c3t/.gvm/scripts/gvm
6 然后我们安装一个golang ,安装默认的版本,时间有点长
执行 ,
gvm install go1
7 编译时报错,暂时不知道什么原因
# Building C bootstrap tool. cmd/dist # Building compilers and Go bootstrap tool for host, linux/amd64. lib9 libbio libmach misc/pprof cmd/addr2line cmd/cov cmd/nm cmd/objdump cmd/pack cmd/prof cmd/cc /home/c3t/.gvm/gos/go1/src/cmd/cc/funct.c: In function ‘dclfunct’: /home/c3t/.gvm/gos/go1/src/cmd/cc/funct.c:273:13: error: iteration 94u invokes undefined behavior [-Werror=aggressive-loop-optimizations] f->sym[o] = S; ^ /home/c3t/.gvm/gos/go1/src/cmd/cc/funct.c:272:2: note: containing loop for(o=0; o<sizeof(f->sym); o++) ^ cc1: all warnings being treated as errors go tool dist: FAILED: gcc -Wall -Wno-sign-compare -Wno-missing-braces -Wno-parentheses -Wno-unknown-pragmas -Wno-switch -Wno-comment -Werror -fno-common -ggdb -O2 -c -m64 -I /home/c3t/.gvm/gos/go1/include -I /home/c3t/.gvm/gos/go1/src/cmd/cc -o $WORK/funct.o /home/c3t/.gvm/gos/go1/src/cmd/cc/funct.c
8 所以使用以下命令安装,1.4是最新版,但是安装失败了。
gvm install 1.4 -B
9 最后下载 golang的sdk 然后在path下配置环境变量