最近用回了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下配置環境變數