Zerlaer's Notebook

欢迎来到我的博客|

Envar-开发环境配置工具使用说明

项目地址:https://github.com/zerlaer/envar

功能特性

  • Go环境配置

    • 设置GOPATH工作区路径
    • 配置GOPROXY代理(默认使用国内镜像)
    • 启用GO111MODULE模块支持
  • Python环境配置

    • 设置pip国内镜像源
  • Node.js环境配置

    • 配置npm国内镜像

系统要求

  • Go 1.16+(用于编译程序)
  • Windows、Linux或macOS操作系统
  • 在Windows上设置系统环境变量时需要管理员权限

使用方法

1. 编译程序

基本编译

go build -o envar main.go

带图标编译(Windows)

如果需要为Windows可执行文件添加图标,请先确保icon.ico文件存在,然后执行:

go run github.com/akavel/rsrc -ico icon.ico -o envar.syso
go build -o envar.exe main.go

2. 配置环境

编辑config.yaml文件,根据需要修改各环境的配置参数:

go:
  gopath: "D:\Code\Go"
  goproxy: "https://goproxy.cn,direct"
  go111module: "on"

python:
  pip_mirror: "https://pypi.tuna.tsinghua.edu.cn/simple"

node:
  npm_mirror: "https://registry.npmmirror.com"

3. 运行程序

Windows

在Windows上,需要以管理员身份运行命令提示符或PowerShell:

# 以管理员身份运行命令提示符或PowerShell
envar.exe

Linux/macOS

# Linux
./envar

# macOS
./envar

配置说明

Go环境

  • gopath:Go工作区路径
  • goproxy:Go模块代理地址
  • go111module:Go模块支持开关(on/off/auto)

Python环境

  • pip_mirror:pip镜像源地址

Node.js环境

  • npm_mirror:npm镜像源地址

国内镜像推荐

Go代理

  • https://goproxy.cn,direct(七牛云)
  • https://goproxy.io,direct(全球)

Python pip镜像

  • https://pypi.tuna.tsinghua.edu.cn/simple(清华大学)
  • https://mirrors.aliyun.com/pypi/simple(阿里云)

Node.js镜像

  • https://registry.npmmirror.com(网易)
  • https://registry.npmmirror.com(淘宝,已迁移至网易)

环境变量持久化说明

程序会根据不同的操作系统,提示用户将环境变量添加到相应的配置文件中:

  • Windows:使用setx /m命令直接设置系统级环境变量
  • Linux:提示添加到/etc/profile文件
  • macOS:提示添加到~/.zshrc文件

注意事项

  1. 在Windows上设置系统环境变量需要管理员权限
  2. 配置更改后可能需要重新启动命令提示符或IDE才能生效
  3. Linux和macOS系统下,需要手动将环境变量添加到配置文件中以实现持久化
  4. 程序运行时会保持控制台窗口不关闭,按任意键即可退出
  5. 如果图标未正确显示,请尝试刷新系统图标缓存或重新启动计算机

项目结构

envar/
├── main.go          # 主程序代码
├── config.yaml      # 配置文件
├── LICENSE          # MIT许可证
├── README.md        # 项目说明文档
├── .gitignore       # Git忽略文件
├── icon.ico         # 程序图标
└── go.mod           # Go模块依赖

许可证

MIT License - 详见 LICENSE 文件