You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无管理员权限安装Ruby on Rails及其他gems的方法

Installing Rails & Gems to a Custom Directory (No Admin Permissions)

Absolutely! You totally can install Rails and all your gems to a custom directory you have full write access to, and set things up so the commands work just like a system-wide install. Since you already have Homebrew, I’ll walk you through two solid approaches—one that tweaks your gem paths directly, and a better long-term solution using a Ruby version manager (which avoids headaches with that ancient system Ruby 2.0.0).

Method 1: Directly Customize Gem Installation Paths

This works if you want to stick with the system Ruby, but keep in mind: Ruby 2.0.0 is extremely outdated and won’t support most modern Rails versions. Use this only if you’re working with legacy projects.

  • Create your custom gem folders in your home directory (this structure keeps things organized):

    mkdir -p ~/.ruby-gems/{bin,gems,specs}
    
  • Update your shell config to tell gem and your system where to look for these files. Depending on your shell, edit either ~/.bash_profile, ~/.bashrc, or ~/.zshrc:

    # Add these lines at the end of the file
    export GEM_HOME="$HOME/.ruby-gems/gems"
    export GEM_PATH="$HOME/.ruby-gems/gems"
    export PATH="$HOME/.ruby-gems/bin:$PATH"
    
  • Reload your shell to apply the changes right away:

    # For Bash users
    source ~/.bash_profile
    # For Zsh users
    source ~/.zshrc
    
  • Install Rails—gem will now install everything to your custom folder instead of the restricted system directory:

    gem install rails
    
  • Verify it works by checking the Rails version:

    rails --version
    

The system Ruby is way too old for modern Rails development. rbenv is a lightweight tool that lets you install recent Ruby versions entirely in your home folder (no admin rights needed) and manage multiple versions for different projects. Since you have Homebrew, this is the easiest and most maintainable option:

  • Install rbenv via Homebrew:

    brew install rbenv
    
  • Initialize rbenv to integrate it with your shell. Run this command and follow the on-screen instructions to add the required line to your shell config file:

    rbenv init
    
  • Reload your shell to activate rbenv:

    # For Bash
    source ~/.bash_profile
    # For Zsh
    source ~/.zshrc
    
  • Install a modern Ruby version (run rbenv install --list to see all available stable releases—3.2.2 is a great choice right now):

    rbenv install 3.2.2
    
  • Set this Ruby version as your global default:

    rbenv global 3.2.2
    
  • Install Rails—it will be tied to this Ruby version and installed in your home folder:

    gem install rails
    
  • Refresh rbenv's command shims so your system recognizes the new rails command:

    rbenv rehash
    
  • Verify everything is working:

    ruby --version  # Should show 3.2.2 (or the version you installed)
    rails --version # Should show the latest Rails version you installed
    

Why This Is Better

Using a version manager like rbenv isolates your Ruby environment from the system one, so you’ll never have to fight permission errors again. It also lets you switch between Ruby versions for different projects if you need to—super handy for legacy work!

内容的提问来源于stack exchange,提问作者tposs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:54:53