Centos7安装golang并配置
1 下载并安装
# 以go1.18.7为例子
# 将安装包解压放到到usr/local中,并解压
cd /usr/local
wget https://golang.google.cn/dl/go1.18.7.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.18.7.linux-amd64.tar.gz
2 配置环境变量
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
3 查看版本
go version
新建文本保存为install.sh,内容为下方 #!/bin/bash if [ -z "$1" ]; then echo "usage: ./install.sh go-package.tar" exit fi if [ -d "/usr/local/go" ]; then echo "Uninstalling old version..." sudo rm -rf /usr/local/go fi echo "Installing..." sudo tar -C /usr/local -xzf $1 echo "Done"
与压缩包放在同一文件夹
cd到所在目录,执行下方代码
sh install.sh go1.19.12.linux-amd64.tar.gz