Files
scripts/install_go.sh
2026-03-28 13:38:22 +08:00

49 lines
1.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
echo "=== Jenkins 安装 Go 1.25.0 ==="
# 核心修改:先检查 Go 是否已安装并能正确显示版本
echo "检查现有 Go 版本..."
if go version &> /dev/null; then
echo "✅ 系统已安装 Go版本为: $(go version)"
echo "无需重新安装,跳过安装步骤。"
exit 0
else
echo "⚠️ 未检测到有效的 Go 安装,开始安装流程..."
fi
# 下载
echo "下载 Go 1.25.0..."
curl -fsSL -o /tmp/go1.25.0.tar.gz "https://dl.google.com/go/go1.25.0.linux-amd64.tar.gz"
if [ $? -eq 0 ]; then
echo "✅ 下载成功"
else
echo "❌ 下载失败"
exit 1
fi
# 安装
echo "解压安装..."
sudo tar -xzf /tmp/go1.25.0.tar.gz -C /usr/local
sudo mv /usr/local/go /usr/local/go-1.25.0
# 创建链接
echo "创建符号链接..."
sudo ln -sf /usr/local/go-1.25.0/bin/go /usr/bin/go
sudo ln -sf /usr/local/go-1.25.0/bin/gofmt /usr/bin/gofmt
# 设置环境
export GOROOT="/usr/local/go-1.25.0"
export PATH="/usr/local/go-1.25.0/bin:$PATH"
# 验证
echo "验证安装..."
/usr/local/go-1.25.0/bin/go version
if [ $? -eq 0 ]; then
echo "✅ Go 1.25.0 安装成功!"
else
echo "❌ 安装失败"
exit 1
fi
echo "安装完成"