linux系統 go 語言安裝


1,下載

https://golang.google.cn/dl/

wget https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz

2.解壓安裝

https://golang.google.cn/doc/install

 tar -C /usr/local -xzf go1.13.5.linux-amd64.tar.gz

3.添加環境變量

export PATH=$PATH:/usr/local/go/bin #重啟系統會消失

配置所有用戶
所以需添加到用戶/etc/profile文件末

 

 

  執行 source /etc/profile

 GOROOT為go安裝目錄

 GOPATH為工作目錄 如 go get 下載的文件會放到該目錄下,

 GOOBIN為生成文件可運行目錄

只配置當前用戶

export GOROOT=/usr/local/go
export GOPATH=~/goproject
export GOBIN=~/gobin
export PATH=$PATH:$GOROOT/bin:$GOBIN

將上邊內容加入~/.profile
我的測試機centos7加入到文件末 /root/.bash_profile 

source   /root/.bash_profile 

4.測試

go version 顯示版本信息
go version go1.13.5 linux/amd64

創建  hello.go 

cd ~/goproject

 vi hello.go

package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}

 go build hello.go 

 

 

 

 測試成功

 5.Go 模塊代理設置,解決國外網站模塊下載慢或不能下載問題

linux下

echo "export GOPROXY=https://goproxy.cn" >> ~/.bash_profile && source ~/.bash_profile

 go env -w GOPROXY=https://goproxy.cn,direct

windows

 打開你的 PowerShell 並執行:

C:\> $env:GOPROXY = "https://goproxy.cn"

 參考文檔

https://golang.google.cn/doc/install

https://github.com/goproxy/goproxy.cn/blob/master/README.md





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM