惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
V
Vulnerabilities – Threatpost
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
Latest news
Latest news
博客园 - 三生石上(FineUI控件)
美团技术团队
aimingoo的专栏
aimingoo的专栏
Google Online Security Blog
Google Online Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
Y
Y Combinator Blog
T
Tailwind CSS Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
C
Cyber Attacks, Cyber Crime and Cyber Security
小众软件
小众软件
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tenable Blog
W
WeLiveSecurity
L
LINUX DO - 热门话题
D
Docker
Cyberwarzone
Cyberwarzone
量子位
A
About on SuperTechFans
The Last Watchdog
The Last Watchdog
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
P
Palo Alto Networks Blog
The Hacker News
The Hacker News
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Full Disclosure
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
O
OpenAI News
Hacker News - Newest:
Hacker News - Newest: "LLM"
Scott Helme
Scott Helme
IT之家
IT之家
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
L
Lohrmann on Cybersecurity
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News

十二的编程笔记

26 年新年前 vibe coding 感慨 - 随便写写 社区驱动型流量的转化效能与质量特征分析 - AI - 计算机科学 ClawdBot 祛魅 2 小时安装 + 实际体验 还需再练练 - AI - 计算机科学 golang 标准库源码解析 - runtime2 GMP - Lib - GO - 计算机科学 BCTF2025-AI - BCTF2025 - CTF - 计算机科学 BCTF2025-MISC-01~08 - BCTF2025 - CTF - 计算机科学 golang 标准库源码解析 - channel - Lib - GO - 计算机科学 golang 标准库源码解析 - Context - Lib - GO - 计算机科学 cloudflare connect 踩坑记录 - Project - 计算机科学 BCTF2024-WEB-01~08 - BCTF2024 - CTF - 计算机科学 BCTF2024-MISC - BCTF2024 - CTF - 计算机科学 Hexo 使用 github Action 进行发布 - Project - 计算机科学 BCTF2024-IOT - BCTF2024 - CTF - 计算机科学 BCTF2024-REVERSE - BCTF2024 - CTF - 计算机科学 分布式事务 - 高可用 - 计算机科学 分布式 CAP 和 BASE 理论 简介 - 高可用 - 计算机科学 搭建使用 Cloudflare Worker 的 Docker 镜像 - Project - 计算机科学 GitHub Copilot 封号及退款过程 - Project - 计算机科学 记录一次 innodb 全表 update - MySQL - Database - 计算机科学
golang 多版本环境控制 - GO - 计算机科学
本文作者: Twelveeee @十二的编程笔记 · 2025-02-28 · via 十二的编程笔记

# 前言

新老项目很多,但是不同项目有不同的 go 版本,在同一个环境管理 go 相当麻烦,后面看文档发现了别人推荐的版本控制工具,基本无感管理 go 版本

# smart-go-dl

Go 多版本管理辅助工具,可以快速安装 Go (次要版本) 的最新版本,并对过期版本进行清理。

项目地址: https://github.com/fsgo/smart-go-dl

# 安装

有 go 环境 使用 go install 安装

go install github.com/fsgo/smart-go-dl@latest

无 go 环境 直接下载二进制文件运行

https://github.com/fsgo/smart-go-dl/releases

# 配置环境变量

export GOBIN=$HOME/go/bin   
export PATH=$GOBIN:$PATH    

# 安装不同的 go 版本

smart-go-dl install go1.22.5

# bin-auto-switcher

Go 自动切换 go 的版本

项目地址: https://github.com/fsgo/bin-auto-switcher

# 安装

go install github.com/fsgo/bin-auto-switcher/bas@latest

# 配置

让 bas 替换 go

cd ~/go/bin/
mv go go_backup
ln -s bas go

新增配置 ~/.config/bas/go.toml

[[Rules]]
Cmd = "go.latest"          
[Rules.Spec]
GoVersionFile = "go.mod"  
GoWork = "auto"
[[Rules]]
Dir = ["~/workspace/fsgo/myserver"]
Cmd = "go1.19"

bas 的本质是替换了 go 的命令,然后通过读取各种配置,比如 go.mod 去判断应该执行的 go 的版本

# 演示

bin-auto-switch go 版本是 go1.22

ddns-go go 版本是 go1.20

直接运行 go 命令就能直接使用

image-20250228191747816

image-20250228191902509