自动安装

1
2
3
4
5
6
7
8
9
# It is recommended to clear the `GOROOT`, `GOBIN`, and other environment variables before installation.
curl -sSL https://raw.githubusercontent.com/voidint/g/master/install.sh | bash
cat << 'EOF' > > ~/.bashrc
# Check if the alias 'g' exists before trying to unalias it
if [[ -n $(alias g 2 >/dev/null) ]]; then
unalias g
fi
EOF
source "$HOME/.g/env "

手动安装

创建目录 GOROOT

1
mkdir ~/.g

从 github releases 下载二进制压缩文件并将其解压到目录 GOBIN 的子目录中 GOROOT(即 GOBIN

1
2
mkdir  ~/.g/bin
tar -xzvf g1.7.0.linux-amd64.tar.gz -C ~/.g/bin

将必要的环境变量写入 GOROOT 文件

1
2
3
4
5
6
7
cat >~/.g/env <<'EOF'
#!/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

导入 GOBIN 到 shell 环境配置文件

1
2
3
4
5
6
cat >>~/.bashrc <<'EOF'
# g shell setup
if [ -f "${HOME}/.g/env" ]; then
. "${HOME}/.g/env"
fi
EOF

启用环境变量。

1
source ~/.bashrc # source ~/.zshrc