CoolFace
Apppublic

xmeta-dev/agent-base

sourceHugging Faceapache-2.0updated 3mo agoView on Hugging Face
0likes
install-go.sh52 linesDownload Raw Back to scripts
1#!/bin/sh2set -e3 4# ============================================================5# Go 开发环境安装脚本6# 安装 Go 官方发行版到 /usr/local/go7# 依赖: wget, ca-certificates8# 全局变量: GOROOT, GOPATH, GO111MODULE9# ============================================================10 11GO_VERSION="${GO_VERSION:-1.26.4}"12GOROOT="/usr/local/go"13GOPATH="${GOPATH:-/root/go}"14GO_TARBALL="go${GO_VERSION}.linux-amd64.tar.gz"15GO_DOWNLOAD_URL="https://go.dev/dl/${GO_TARBALL}"16 17echo ">>> Installing Go ${GO_VERSION} ..."18 19# 下载 Go 二进制发行版20wget -q "${GO_DOWNLOAD_URL}" -O "/tmp/${GO_TARBALL}"21 22if [ ! -f "/tmp/${GO_TARBALL}" ]; then23    echo "Error: Failed to download Go tarball from ${GO_DOWNLOAD_URL}"24    exit 125fi26 27# 移除旧版本并解压到 /usr/local28rm -rf "${GOROOT}"29tar -C /usr/local -xzf "/tmp/${GO_TARBALL}"30 31# 创建 GOPATH 目录32mkdir -p "${GOPATH}" "${GOPATH}/bin"33 34# 写入 profile.d 环境变量(登录 shell 自动加载)35cat > /etc/profile.d/go.sh << 'PROFILEEOF'36# Go 开发环境37export GOROOT=/usr/local/go38export GOPATH=${GOPATH:-/root/go}39export GO111MODULE=on40export PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}"41PROFILEEOF42chmod +x /etc/profile.d/go.sh43 44# 当前构建会话也可用45export PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}"46 47# 清理下载文件48rm -f "/tmp/${GO_TARBALL}"49 50echo ">>> Go ${GO_VERSION} installed successfully."51echo "    $(go version)"52