centos下安裝go一般 有兩種方式约计,一個是yum苍糠,一個是直接到官網下載.tar.gz包
yum方式安裝比較簡單 直接執(zhí)行
yum install golang
然后就可以使用go語言了雅镊,這種方式有著明顯的缺點左刽,因為都是yum自己處理的依賴捺信,不方便管理
第二種方式是到官網下載.tar.gz包
標準官網:https://golang.org/ 需要墻
鏡像官網:https://golang.google.cn/dl/ 【國內推薦】
本次安裝的是1.13.5
[root@iZgj43d7rgpp6qZ local]# wget https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz
[root@iZgj43d7rgpp6qZ local]# tar -zxf go1.13.5.linux-amd64.tar.gz -C /usr/local
將go添加到環(huán)境變量
[root@iZgj43d7rgpp6qZ local]# vim /etc/profile
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
if [ -n "${BASH_VERSION-}" ] ; then
if [ -f /etc/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bashrc
# Check for double sourcing is done in /etc/bashrc.
. /etc/bashrc
fi
fi
export GO111MODULE=on
export GOROOT=/usr/local/go
export GOPATH=/home/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
重點是后面那部分
export GO111MODULE=on
export GOROOT=/usr/local/go
export GOPATH=/home/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
保存退出后使用環(huán)境變量生效
[root@iZgj43d7rgpp6qZ local]# source /etc/profile
[root@iZgj43d7rgpp6qZ local]# go version
go version go1.13.5 linux/amd64
安裝完畢