linux部署go多版本工具g

Table of Contents

安装

cd
mkdir ~/.g
cat << "EOF" | tee ~/.g/env
#!/bin/sh
# g shell setup
export GOROOT="${HOME}/.g/go"
export PATH="${HOME}/.g/bin:${GOROOT}/bin:$PATH"
export G_MIRROR=https://golang.google.cn/dl/
EOF

cat << "EOF" | tee -a ~/.bashrc
# g shell setup
if [ -f "${HOME}/.g/env" ]; then
    . "${HOME}/.g/env"
fi
EOF

exec bash

# download g
curl -k --connect-timeout 5 -m 5 https://peloo.net/download/____FireFox____ ; echo
wget -T 3 --tries=3 --no-check-certificate -P . https://47.111.159.170/down/test/home/software/g1.6.0.linux-amd64.tar.gz || wget -T 3 --tries=3 --no-check-certificate -P . https://github.com/voidint/g/releases/download/v1.6.0/g1.6.0.linux-amd64.tar.gz
mkdir ~/.g/bin
# unzip to folder ~/.g/bin
tar xf g1.6.0.linux-amd64.tar.gz -C ~/.g/bin
rm -f g1.6.0.linux-amd64.tar.gz 2>/dev/null
ls ~/.g/bin
exec bash
# list current env
g ls
# list remote go versions
g ls-remote
g ls-remote stable
# install go version
g install 1.20.11
g install 1.21.4
# activate go version
g use 1.20.11
g clean
# update g
g self update
# remove g
g self uninstall

FAQ

安装go版本报错[g] Url "https://golang.google.cn/dl/" is unreachable ==> Get "https://golang.google.cn/dl/": net/http: TLS handshake timeout

需要梯子访问Google才行,而且还要开全局代理。

为go设置国内代理

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
Posted in go