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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

十二的编程笔记

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 - 计算机科学
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   # go install 安装的二进制文件所在目录,go1.x 命令也将安装到此目录
export PATH=$GOBIN:$PATH    # 可以直接在任意位置使用 GOBIN 目录下的所有命令

# 安装不同的 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
# 替换 go
ln -s bas go

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

[[Rules]]
Cmd = "go.latest"          # 默认执行命令 (必填) 如果命令不存在不报错
[Rules.Spec]
GoVersionFile = "go.mod"  #判断 go 版本的文件
GoWork = "auto"
# 单独指定哪个目录使用的 go 版本
[[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