介绍
mise(发音同 "mice")是一款用 Rust 编写的高性能多运行时版本管理器,它能够帮助开发者在单个工具中统一管理多种编程语言和工具的版本。
核心价值
-
多语言统一管理
:支持 Node.js、Python、Ruby、Go、Java、Rust 等多种语言和工具的版本管理
-
高性能
:基于 Rust 开发,执行速度快,启动时间短
-
统一接口
:使用一致的命令行界面管理所有语言版本,无需学习多种工具
-
项目级配置
:通过配置文件在团队中共享工具版本,确保开发环境一致性
-
兼容性
:兼容 asdf 插件系统,支持多种版本文件格式(如 .nvmrc、.python-version)
-
任务管理
:内置任务系统,可以替代 npm 或 make 等工具
安装
macOS、Linux 或 WSL
使用官方安装脚本:
go
curl https://mise.run | sh
或者使用 Homebrew(macOS/Linux):
go
brew install mise
配置 Shell
将 mise 添加到你的 shell 配置文件中:
对于 Bash (~/.bashrc):
go
echo 'eval "$("$HOME/.local/bin/mise" activate bash)"'>>~/.bashrc
重新加载配置:
go
source ~/.bashrc # 或 source ~/.zshrc
验证安装
go
mise --version
常用命令
基础命令
go
# 查看所有可用的运行时(语言/工具)mise ls-remote# 查看已安装的版本mise list# 查看当前激活的版本mise current# 安装特定版本mise use -g node@20# 设置全局默认版本mise use -g python@3.12# 在项目目录设置本地版本mise use node@20# 卸载某个版本mise uninstall node@20
版本文件管理
go
# 查看当前项目使用的版本配置mise ls# 创建或更新 .tool-versions 文件mise use node@20 python@3.12# 读取 .tool-versions 或其他版本文件mise sync
插件管理
go
# 列出所有可用插件mise plugins ls-remote# 搜索特定语言的插件mise plugins ls-remote | grep node# 添加自定义插件mise plugins add node https://github.com/asdf-vm/asdf-nodejs.git
各语言使用指南
Node.js
安装 Node.js
go
# 安装最新 LTS 版本mise use -g node@lts# 安装特定版本mise use -g node@20.11.0# 安装最新版本mise use -g node@latest# 在项目中设置版本cd /path/to/projectmise use node@20
管理多个 Node.js 版本
go
# 查看已安装的 Node.js 版本mise list node# 查看可用的 Node.js 版本mise ls-remote node# 切换全局版本mise use -g node@18# 临时使用某个版本(仅当前会话)mise exec node@20 -- node --version
配合 npm 使用
go
# 使用 mise 安装的 Node.js 会自动配置 npmnpm install -g yarnnpm install -g pnpm
项目配置示例
在项目根目录创建 .tool-versions 文件:
go
node 20.11.0
或创建 .mise.toml 文件:
go
[tools]node ="20.11.0"
Python
安装 Python
go
# 安装最新稳定版mise use -g python@latest# 安装特定版本mise use -g python@3.12.0# 安装 Python 3.11mise use -g python@3.11# 在项目中设置版本mise use python@3.12
管理虚拟环境
go
# 创建虚拟环境python -m venv .venv# 激活虚拟环境source .venv/bin/activate # Linux/macOS.venv\Scripts\activate # Windows# 退出虚拟环境deactivate
配合 pip 使用
go
# 升级 pippip install --upgrade pip# 安装包pip install requests# 导出依赖pip freeze > requirements.txt# 从 requirements.txt 安装pip install -r requirements.txt
项目配置示例
.tool-versions:
go
python 3.12.0
.mise.toml:
go
[tools]python ="3.12.0"
Go
安装 Go
go
# 安装最新版本mise use -g go@latest# 安装特定版本mise use -g go@1.22.0# 安装 Go 1.21mise use -g go@1.21# 在项目中设置版本mise use go@1.22
配置 Go 环境
mise 会自动设置 GOPATH 和 GOROOT 环境变量:
go
# 查看 Go 环境信息go env# 查看当前 Go 版本go version
Go Module 使用
go
# 初始化模块go mod init example.com/myproject# 添加依赖go get github.com/gin-gonic/gin# 下载依赖go mod download# 整理依赖go mod tidy# 构建项目go build# 运行项目go run main.go
项目配置示例
.tool-versions:
go
go 1.22.0
.mise.toml:
go
[tools]go ="1.22.0"
高级配置
.mise.toml 配置文件
在项目根目录创建 .mise.toml 文件进行更详细的配置:
go
[tools]# 指定版本node ="20.11.0"python ="3.12.0"go ="1.22.0"# 使用最新版本node ="latest"# 使用前缀匹配python ="3.12"[env]# 设置环境变量NODE_ENV ="development"PYTHONPATH ="./src"[alias]# 创建版本别名node18 ="node@18"node20 ="node@20"
任务系统
mise 内置任务系统,可以定义和运行任务:
go
[tasks.build]run ="npm run build"[tasks.test]run ="npm test"[tasks.lint]run ="eslint src/"
运行任务:
go
# 列出所有任务mise tasks# 运行任务mise run build# 并行运行多个任务mise run build test
实用技巧
查看某个版本的安装路径
go
mise where node@20mise where python@3.12
临时使用某个版本
go
mise exec node@18 -- npm installmise exec python@3.11-- python script.py
自动切换版本
mise 会在进入目录时自动读取并切换到 .tool-versions 或 .mise.toml 中定义的版本。
清理缓存
go
mise cache clear
更新 mise
go
mise self-update
常见问题
Q: mise 和 asdf 有什么区别?
A: mise 是用 Rust 编写的,性能更好,启动更快。它兼容 asdf 的插件系统,可以作为 asdf 的替代品。
Q: 如何在项目中固定版本?
A: 在项目根目录创建 .tool-versions 或 .mise.toml 文件,团队成员会自动使用相同的版本。
Q: 忘记安装某个版本怎么办?
A: mise 会在你切换到某个版本时自动下载安装,无需手动预装。
Q: 如何查看所有可用的工具和版本?
A: 使用 mise ls-remote 查看所有可用的运行时,mise ls-remote node 查看特定语言的版本。
Q: 本地已安装了 npm 全局包,如何迁移到 mise?
A: 这是一个常见问题。本地系统安装的 npm 全局包不会自动出现在 mise 管理的 Node.js 中。完整的迁移步骤如下:
迁移全局包清单
第 1 步:导出当前全局包列表
go
npm list -g --depth=0>~/Desktop/npm-global-packages.txt
第 2 步:提取可安装的包名
go
npm list -g --depth=0--json | jq -r '.dependencies | keys[]'>~/Desktop/packages-to-install.txt
第 3 步:切换到 mise 管理的 Node.js
go
# 设置全局 Node 版为你原来的版本(比如 18)mise use -g node@18# 验证切换成功node --versionnpm --version
第 4 步:重新安装所有全局包
go
# 方式 1:逐个安装(推荐,能看到进度)cat ~/Desktop/packages-to-install.txt | xargs npm install -g# 方式 2:一次性安装npm install -g $(cat ~/Desktop/packages-to-install.txt)
第 5 步:验证安装
go
npm list -g --depth=0# 验证关键包是否工作yarn --versionpm2 --version
可能遇到的问题及解决方案
| 问题 | 解决方案 |
|---|---|
| 某些包安装失败 | 检查该包是否需要特定的 Node 版本或系统依赖 |
| 权限错误(EACCES) | 通常 mise 安装的 npm 不会有权限问题,但如果有,用 npm config set prefix ~/.npm-global |
| 包版本不一致 | 如果需要特定版本,编辑 packages-to-install.txt,改为 package@version 格式 |
| jq 命令未安装 | macOS: brew install jq;Linux: sudo apt install jq;Windows: 从 https://stedolan.github.io/jq/ 下载 |
完整自动化脚本
如果你想要一步到位,可以创建迁移脚本:
go
#!/bin/bash# 1. 导出包列表echo "导出当前全局包..."npm list -g --depth=0--json | jq -r '.dependencies | keys[]'>/tmp/npm-packages.txt# 2. 切换到 mise 管理的 Nodeecho "切换到 mise Node..."mise use -g node@18 # 改成你需要的版本# 3. 重新安装echo "重新安装全局包(可能需要几分钟)..."cat /tmp/npm-packages.txt | xargs npm install -g# 4. 验证echo "验证安装..."npm list -g --depth=0| head -20echo "迁移完成!"
清理旧的系统 npm(可选)
迁移成功后,如果想完全统一到 mise 管理,可以卸载系统 Node.js:
go
# macOSbrew uninstall node# Linux (apt)sudo apt remove nodejs npm# Windows# 使用控制面板或 scoop uninstall nodejs
这样可以避免版本混乱的问题。
参考资源
-
mise 官方文档
-
mise GitHub 仓库
-
支持的运行时列表