macos管理本地golang的多版本sdk

背景

无论你是哪个编程语言的开发者,例如 Java、Go 等,通常在本地开发过程中,你经常需要安装相应的 SDK。由于各种原因,往往需要在不同的项目中来回切换多个版本的 SDK。

安装步骤

1.安装homebrew

bash 复制代码
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

详细步骤参考:macos系统安装homebrew包管理工具_mac os 管理工具-CSDN博客

2.安装Wget

bash 复制代码
brew install wget

3.安装多版本管理工具

(1)安装前清空手动安装的`GOROOT`、`GOBIN`等环境变量

bash 复制代码
# 注释掉goroot、gobin等环境变量
sudo vi ~/.bash_profile
source ~/.bash_profile

(2)一键安装g工具

bash 复制代码
# 建议安装前清空`GOROOT`、`GOBIN`等环境变量
$ curl -sSL https://raw.githubusercontent.com/voidint/g/master/install.sh | bash
$ echo "unalias g" >> ~/.bashrc # 可选。若其他程序(如'git')使用了'g'作为别名。
$ source "$HOME/.g/env"

(3)列出可用的 Go 版本

bash 复制代码
g ls-remote

(4)安装特定版本的 Go

bash 复制代码
g install 1.21.5

(5)切换到特定版本的 Go

bash 复制代码
g use 1.21.5

(6)查看go版本

bash 复制代码
go version

4.g工具使用教程

参考:https://github.com/voidint/g/blob/master/README_CN.md

结束

相关推荐
avilang16 小时前
如何在 Go 1.24+ 中管理 tool 依赖
go
程序员爱钓鱼16 小时前
用 Go 做浏览器自动化?chromedp 带你飞!
后端·go·trae
极简之美17 小时前
Mac 远程连接 Windows 简明教程(2025 实测版)
windows·macos
q***046319 小时前
[golang][MAC]Go环境搭建+VsCode配置
vscode·macos·golang
斌蔚司李21 小时前
笔记本、台式机、平板二合一?Mac、Win、Linux?
linux·macos·电脑
lichong95121 小时前
harmonyos 大屏设备怎么弹出 u 盘
前端·macos·华为·typescript·android studio·harmonyos·大前端
打工人11121 小时前
安卓Android 获取mac地址及sn
android·macos
飞火流星0202721 小时前
MacOS 12(Monterey )PG安装通关指导
macos·postgresql16·mac安装pg·mac brew安装pg16
喵霓1 天前
mac系统的环境变量-bash_profile
开发语言·macos·bash
Bruce_Liuxiaowei1 天前
[特殊字符] Mac 高效排查:使用 lsof 查找和管理端口占用进程
网络·macos