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

Mac M1本地运行Jekyll博客遇bundle install权限错误求助

问题描述

在Mac M1本地部署基于Minimal Mistakes主题的Jekyll博客时,卡在bundle install步骤,多次尝试均失败,出现无法删除旧gem安装包的权限错误,涉及commonmarker、gemoji、racc等组件。已尝试过rbenv但无效果,求助如何解决该权限问题,以及是否有办法删除/Library/Ruby/Gems/2.6.0目录下无权限访问的gem文件。

附当前使用的Gemfile内容:

source "https://rubygems.org"
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
#
#     bundle exec jekyll serve
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
# This is the default theme for new Jekyll sites. You may change this to anything you like.
# gem "minimal-mistakes-jekyll"
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
gem "github-pages", "~> 226", group: :jekyll_plugins
gem "jekyll-include-cache", group: :jekyll_plugins
# If you have any plugins, put them here!
group :jekyll_plugins do
  gem "jekyll-feed", "~> 0.12"
end

# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
platforms :mingw, :x64_mingw, :mswin, :jruby do
  gem "tzinfo", "~> 1.2"
  gem "tzinfo-data"
end

# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin]

# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem
# do not have a Java counterpart.
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]

gem "webrick", "~> 1.7"
gem "jekyll-spaceship"
解决方案

一、搞定bundle install的权限报错

  • 直接用bundle本地安装:绕开系统Ruby目录的权限坑,把所有依赖装在项目自己的目录里。执行这条命令:

    bundle install --path vendor/bundle
    

    之后启动Jekyll就用bundle exec jekyll serve,所有gem都存在项目的vendor/bundle里,完全不用碰系统级的Ruby目录。

  • 把rbenv配置弄对(之前没生效可能是没初始化好):

    1. 先把rbenv的初始化脚本加到shell配置里(M1默认用zsh,所以改~/.zshrc):
      echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc
      
      重启终端或者执行source ~/.zshrc让配置生效。
    2. 装个适配M1的Ruby版本(比如3.2.2,别用系统自带的2.6了):
      rbenv install 3.2.2
      rbenv local 3.2.2
      
      再跑bundle install,这时gem会装在rbenv管理的用户目录下,根本不会涉及系统目录的权限问题。

二、删除/Library/Ruby/Gems/2.6.0里无权限的gem

  • 用sudo强制删指定gem:系统目录需要管理员权限,直接针对报错的组件删:
    sudo rm -rf /Library/Ruby/Gems/2.6.0/gems/commonmarker-*
    sudo rm -rf /Library/Ruby/Gems/2.6.0/gems/gemoji-*
    sudo rm -rf /Library/Ruby/Gems/2.6.0/gems/racc-*
    
    要是想清理整个目录下的gem(谨慎点,系统自带Ruby可能有其他应用依赖),就跑:
    sudo rm -rf /Library/Ruby/Gems/2.6.0/gems/*
    
  • 提醒:别随便删系统Ruby的整个目录,只删报错的那几个gem就行,避免搞坏系统自带的应用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 15:45:36