centos下安装go一般 有两种方式,一个是yum,一个是直接到官网下载.tar.gz包
yum方式安装比较简单 直接执行
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添加到环境变量
[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
保存退出后使用环境变量生效
[root@iZgj43d7rgpp6qZ local]# source /etc/profile
[root@iZgj43d7rgpp6qZ local]# go version
go version go1.13.5 linux/amd64
安装完毕