簡介
go 環境部署很簡單,直接解壓二進制壓縮包就可以完成安裝。
快速安裝腳本
<code>#!/bin/bash
go_version="1.14.linux-amd64"
install_path="/opt/go"
# download golang on studygolang mirror
wget -c -t 0 -T 1200 https://studygolang.com/dl/golang/go${go_version}.tar.gz
tar zxvf go${go_version}.tar.gz
mv go $install_path
if cat ~/.bash_profile | grep 'export GOROOT=' >>/dev/null 2>&1; then
echo "GOROOT is $GOROOT now"
echo -e "if you want to change it ,run command :\\n"
echo "export GOROOT=${install_path} >>~/.bash_profile"
echo "export GOPATH=${HOME}/gopath >>~/.bash_profile"
echo "export PATH=\\${GOROOT}/bin:\\${GOPATH}/bin:\\$PATH >>~/.bash_profile"
else
# set environment
echo "export GOROOT=${install_path}" >>~/.bash_profile
echo "export GOPATH=${HOME}/gopath" >>~/.bash_profile
echo "export PATH=\\${GOROOT}/bin:\\${GOPATH}/bin:\\$PATH" >>~/.bash_profile
fi
# source the env setting
source ~/.bash_profile
# set go mod
go env -w GO111MODULE=on
# set go mod proxy
go env -w GOPROXY=https://goproxy.cn,direct
# show version
go version
echo "You need run \" source ~/.bash_profile \" again !"
/<code>
總結
一鍵安裝:
<code>curl https://gitee.com/op2dev/opscript/raw/master/linux/golang/install_golang.sh | bash
/<code>
閱讀更多 linux運維菜 的文章