【问题标题】:ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory [duplicate]错误:执行 gem 时 ...(Gem::FilePermissionError)您没有 /Library/Ruby/Gems/2.6.0 目录的写权限[重复]
【发布时间】:2021-01-31 08:20:03
【问题描述】:

我正在为我的 Rails 应用程序提供捆绑或安装 gem 的写入权限。

不推荐,但我尝试过使用 sudo gemname install 对我也不起作用。

运行bundle install后无法连接

问题来了

An error occurred while installing puma (4.3.3), and Bundler cannot continue. Make sure that gem install puma -v '4.3.3' succeeds before bundling.

然后我跑 gem install puma -v '4.3.3'

并渲染 ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

我认为这可能会有所帮助。这是我的本地宝石列表


benchmark (default: 0.1.0)
bigdecimal (default: 2.0.0)
bundler (2.1.4, 1.17.3)
cgi (default: 0.1.0)
codecov (0.2.7)
colorize (0.8.1)
csv (default: 3.1.2)
date (default: 3.0.0)
dbm (default: 1.1.0)
delegate (default: 0.1.0)
did_you_mean (default: 1.4.0)
docile (1.3.2)
etc (default: 1.1.0)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.4.1)
forwardable (default: 1.3.1)
getoptlong (default: 0.1.0)
io-console (default: 0.5.6)
ipaddr (default: 1.2.2)
irb (default: 1.2.6)
json (default: 2.3.0)
logger (default: 1.4.2)
matrix (default: 0.2.0)
minitest (5.13.0)
mutex_m (default: 0.1.0)
net-pop (default: 0.1.0)
net-smtp (default: 0.1.0)
net-telnet (0.2.0)
nio4r (2.5.4)
observer (default: 0.1.0)
open3 (default: 0.1.0)
openssl (default: 2.1.2)
ostruct (default: 0.2.0)
power_assert (1.1.7)
prime (default: 0.1.1)
pstore (default: 0.1.0)
psych (default: 3.1.0)
racc (default: 1.4.16)
rake (13.0.1)
rdoc (default: 6.2.1)
readline (default: 0.0.2)
readline-ext (default: 0.1.0)
reline (default: 0.1.5)
rexml (default: 3.2.3)
rss (default: 0.2.8)
sdbm (default: 1.0.0)
simplecov (0.19.0)
simplecov-html (0.12.3)
singleton (default: 0.1.0)
stringio (default: 0.1.0)
strscan (default: 1.0.3)
test-unit (3.3.4)
timeout (default: 0.1.0)
tracer (default: 0.1.0)
uri (default: 0.10.0)
webrick (default: 1.6.0)
xmlrpc (0.3.0)
yaml (default: 0.1.0)
zlib (default: 1.1.0)

我认为这与没有 x-code 命令行有关。

我已经下载了 x-code 命令行并更新了我的系统软件,但我仍然呈现此错误。

我认为这可能与我有关

~/.zshrc 文件

在这里

# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/mvizcaino/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
alias zshconfig= "mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
#export PATH="$PATH:$HOME/.rvm/bin"

# Ruby with rbenv initialize
eval "$(rbenv init -)"

export PATH="/usr/local/opt/ruby/bin:$PATH"

export GEM_HOME=/Users/mvizcaino/gems

export PATH="$HOME/.rbenv/bin:$PATH"

alias brewup='brew update; brew upgrade; brew cleanup; brew doctor'


我不确定还有什么可能导致此错误,但我几乎被此错误所困扰。

【问题讨论】:

  • 这是一个更多与 linux 和权限相关的问题,您的 gem 文件夹可能在 sudo 用户所有权下,您对 'sudo install' 表示什么命令?
  • 我正在使用 mac catalina。大多数文章都指向使用sudo gem install gemname
  • 避免使用 sudo 安装您的 gems,您基本上是在告诉系统以 sudo 用户身份执行程序,但是当您使用您的应用程序时,您将其作为您的个人用户使用,以便现在工作,您应该使用 sudo ruby​​ app.rb 或 sudo rails server...取决于您在做什么...这根本是错误的
  • 我从不在 Mac 上使用 Rails,但本指南看起来很简单 gorails.com/setup/osx/10.15-catalina
  • 等等。该问题暗示您正在尝试sudó bundle install,但在问题中输入错误(我们假设这是因为您列出了您的gemfile。但最后一条评论清楚地表明您的安装命令完全是另外一回事,而不是捆绑器。将问题改写为更清楚向我们展示您运行的内容以及完整的输出。无需猜测 gemfile 或 zsh 配置文件是否相关 - 实际命令和实际输出非常相关。

标签: ruby-on-rails ruby rubygems zshrc


【解决方案1】:

您可以通过将 gems 本地安装到您的项目来避免权限问题

bundle install --path=vendor

如果 bundler 在安装 puma 时仍然给你一个错误,这意味着你的构建工具没有工作。 bundle install 的完整输出应该会告诉您出了什么问题。

错误通常位于“捆绑程序无法继续”消息的正上方

【讨论】:

  • 原来 rbenv 没有在全局状态下配置到 mac 提供的内部 ruby​​ 版本抛出错误。通过运行 rbenv global 2.6.5 解决了这个问题,这是我在这个项目中使用的 ruby​​ 版本
  • 添加到 mvizm2015 之前的评论。他的评论有所帮助,但并没有完全解决问题。通过删除设置要使用的 ruby​​ 版本的 ~/.ruby-version 文件来修复它。这是一个很久以前创建的文件,带有一个完全过时的 ruby​​ 版本,没有安装在 rbenv 中。
猜你喜欢
  • 2021-07-16
  • 2019-11-22
  • 1970-01-01
  • 2019-01-10
  • 2013-09-07
  • 2018-12-10
相关资源
最近更新 更多