linux安裝go以及配置環境

2021-10-07 23:10:35 字數 2086 閱讀 9437

最近搭建服務需要用到go來搭建,之前一直都是在別人搭好的環境下搞,但是由於這次用的時候出現了版本不一致的問題,如下:

# errors

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# runtime/internal/sys

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# internal/race

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# unicode/utf8

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# unicode

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# math/bits

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# crypto/internal/subtle

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# container/list

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# crypto/subtle

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# sync/atomic

compile: version "go1.12.4" does not match go tool version "go1.12.7"

# internal/cpu

compile: version "go1.12.4" does not match go tool version "go1.12.7"

import cycle not allowed

package main

imports fmt

imports errors

imports runtime

imports internal/bytealg

imports internal/cpu

imports runtime

最簡單的go run hello.go都會出錯,迫不得已自己重新搭建了環境,這裡記錄下安裝過程,後續方便查閱:

tar -c /usr/local -xzf go1.14.4.linux-amd64.tar.gz
解壓到指定目錄下,一般不安裝在/usr/local,安裝在自己的路徑下,不造成其他人的干擾,我新建了個golang資料夾,將go的解壓檔案都放在了golang下

安裝好後,會出現bin,src, pkg等檔案,這也就是goroot的路徑,也就是go的安裝路徑

2. 配置路徑

vi ~/.bashrc

例如,我的go都解壓在了/data/mm/golang/go中, goroot設定

export goroot="/data/mm/golang/go"
在/data/mm/golang/中新建bin, src pkg資料夾,將gopath設定為:

export gopath="/data/mm/golang/"
設定path:

export path=$path:/data/mm/golang/go/bin
source ~/.bashrc

執行go version就可以看到最新安裝的go版本,說明就成功了

go環境安裝及配置

參考文章 ubuntu搭建go開發環境 ubuntu設定gopath,goroot環境變數 go優秀開源專案 一 安裝wget https 14.linux amd64.tar.gz sudo mkdir p usr local go sudo tar c usr local xzf go1.14....

Go環境安裝配置

前面我們已經安裝好了虛擬環境,那麼接下來就需要在虛擬環境中安裝go環境了,因此你首先要執行vagrant up把虛擬機器開起來,然後通過vagrant ssh登入到系統中。我們需要修改配置檔案 etc default locale設定為 lang en us.utf 8 language en us...

linux下安裝配置go語言環境

並解壓縮至你想安裝的位置 以 home golang 為例 解壓縮為 tar zxvf 加檔名 如圖 2,配置環境變數 vim bashrc 追加以下內容 export gobin usr lib golang go bin export goroot usr lib golang go expor...