---
title: "Ruby的虚拟环境管理"
url: "https://versun.me/ruby-virtual-environment-management"
markdown_url: "https://versun.me/ruby-virtual-environment-management.md"
format: "note"
published: "2024-11-11T06:29:20.000Z"
updated: "2026-01-05T05:29:45.000Z"
collections:
  - "Blog"
site: "Versun"
---

# Ruby的虚拟环境管理

Ruby官方推荐的环境管理工具有[asdf-vm](https://asdf-vm.com/), [chruby](https://github.com/postmodern/chruby#readme), [rbenv](https://github.com/rbenv/rbenv#readme), [rvm](http://rvm.io/), [uru](https://bitbucket.org/jonforums/uru)  
个人实测下来，最方便的是asdf-vm，测试平台: macOS(M1), Linux X86-64, [Replit IDE](https://replit.com/@ac-replit29742/Ruby-with-asdf-vm?v=1)

简要记录下基础的使用方法：  
**安装asdf-vm**  
按照[官方文档](https://asdf-vm.com/guide/getting-started.html#_3-install-asdf)安装即可  
**安装Ruby插件**  
`asdf plugin add ruby`  
**安装依赖**  
根据[官方文档](https://github.com/rbenv/ruby-build/wiki#suggested-build-environment)安装编译ruby所需要的依赖  
**安装Ruby指定版本**  
`asdf install ruby 3.3.5`  
**设置本地的Ruby版本**  
`asdf local ruby 3.3.5`  
该命令会在当前文件夹中创建`.tool-versions`来记录特定的版本  
**设置全局版本**  
`asdf global ruby 3.3.5`  
全局默认配置在 `$HOME/.tool-versions` 文件中进行管理  
**列出已安装版本**  
`asdf list ruby`  
**列出所有可用版本**  
`asdf list all ruby`  
**显示当前版本**  
`asdf current`
