【问题标题】:ERROR: While executing gem ... (Gem::FilePermissionError)错误:执行 gem 时 ... (Gem::FilePermissionError)
【发布时间】:2013-09-07 03:17:22
【问题描述】:

我已经检查了所有其他类似的答案,没有一个与我的完全一样,这些解决方案也没有一个对我有用。

gem environmentsudo gem environment 给出相同的结果:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.5.3
  - RUBY VERSION: 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/1.8
     - /home/ava/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

rvm -v : rvm 1.22.3

ruby -v : ruby 1.8.7

OSX 10.8.4

echo $PATH /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/ava/.rvm/bin:/home/ava/bin

gem install <gem-name>给了

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /usr/local/lib/ruby/gems/1.8 directory.

而我可以通过 sudo 安装它。我做错了什么?

更新:

根据 cmets 和这个 post,我跑了以下:

rvm implode 然后重新安装稳定版。 rvm install 1.9.3 或任何其他 ruby​​ 安装失败

Error running '__rvm_make -j24',
please read /home/ava/.rvm/log/log/1378418790_ruby-1.9.3-p194/make.log
There has been an error while running make. Halting the installation.

make.log

    [2013-09-05 22:06:48] make
current path: /home/ava/.rvm/src/ruby-1.9.3-p194
command(2): make -j24
        CC = gcc
        LD = ld
        LDSHARED = gcc -shared
        CFLAGS = -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Werror-implicit-function-declaration  -fPIC
        XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT
        CPPFLAGS =   -I. -I.ext/include/x86_64-linux -I./include -I.
        DLDFLAGS = -Wl,-soname,libruby.so.1.9
        SOLIBS = -lpthread -lrt -ldl -lcrypt -lm
compiling main.c
compiling dmydln.c
compiling dmyencoding.c
compiling version.c
compiling miniprelude.c
compiling array.c
compiling bignum.c
compiling class.c
compiling compar.c
compiling complex.c
compiling dir.c
compiling dln_find.c
compiling enum.c
compiling enumerator.c
compiling error.c
compiling eval.c
compiling load.c
compiling proc.c
compiling file.c
:
:
:
In file included from ossl.h:213,
                 from ossl_pkcs5.c:5:
openssl_missing.h:71: error: conflicting types for ‘HMAC_CTX_copy’
/usr/local/include/openssl/hmac.h:102: error: previous declaration of ‘HMAC_CTX_copy’ was here
openssl_missing.h:95: error: conflicting types for ‘EVP_CIPHER_CTX_copy’
/usr/local/include/openssl/evp.h:459: error: previous declaration of ‘EVP_CIPHER_CTX_copy’ was here
make[2]: *** [ossl_pkcs5.o] Error 1
In file included from ossl.h:213,
                 from ossl_x509req.c:11:
:
:
:

【问题讨论】:

  • rvm listwhich ruby 的输出是什么?基本上,您的计算机中安装了两个 ruby​​ 1.8,您需要使用安装在 /home/ava/.gem/ruby/1.8 而不是 /usr/local/lib/ruby/gems/1.8 的那个。将 rvm 设置为使用正确的 ruby​​ 应该可以解决问题。
  • rvm list ext-ree-1.8.7-2011.12 which ruby​​ /usr/local/bin/ruby
  • 试试:rvm remove ext-ree-1.8.7-2011.12rvm install 1.8.2 。 rvm use 'the new ruby​​ version installed' --default
  • rvm install 1.8.2 失败并显示There is no checksum for 'http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.2.tar.gz' or 'ruby-1.8.2.tar.gz', it's not possible to validate it.
  • 我认为 1.8.2 不再受任何支持。它没有保持最新,如果没有大量的手动修复它就无法编译。毕竟,它是在 2004 年发布的。你为什么想要 1.8.2?

标签: ruby macos gem osx-mountain-lion sudo


【解决方案1】:

我尝试将我的 ruby​​ 更新到最新版本使用 酿造红宝石安装

在我获得最新的 ruby​​ 版本后,gem install rails 就可以工作了

【讨论】:

  • 你能解释清楚吗?
【解决方案2】:

这里提到的“写权限”错误和Gem::FilePermissionError 是由于 Ruby 环境配置不正确造成的。您永远不需要使用 sudo 来安装 gems,无论您在 Stack Overflow 上将其视为已接受的答案有多少次。 Here's why.

概括地说,在 Mac 上设置合适的 Ruby 开发环境包括六个步骤:

  1. 安装 Homebrew(它还安装必备的 Apple 命令行工具)
  2. 安装 Ruby 管理器(例如 chruby、rbenv、asdf、RVM) - 其中大部分都可以使用 Homebrew 安装
  3. 通过将适当的行添加到您的 shell 文件(~/.bash_profile~/.zshrc)来配置 Ruby 管理器 - 每个管理器都会有执行此操作的说明,这是人们错过的典型步骤
  4. 重新启动终端(或打开一个新选项卡)以使 shell 更改生效 - 另一个经常被忽略的步骤
  5. 使用 Ruby 管理器安装特定版本的 Ruby
  6. 使用 Ruby 管理器切换到该版本的 Ruby

我的个人偏好是chrubyruby-install。有关更多详细信息和可以自动化整个过程的脚本,请在此处查看我的答案: https://stackoverflow.com/a/54873916/928191

【讨论】:

  • 作为rbenv 用户的一般上下文,如果您没有安装版本(终端open ~/.rbenv/versions/ 应该为每个安装的版本都有一个文件夹),或者如果您没有设置您希望全局/本地使用的版本(例如,rbenv global 3.1.0)。其他可能的原因是未能配置您的 shims 路径。
【解决方案3】:

如果您使用rbenv,您可能忘记启用它:

> rbenv init
# Load rbenv automatically by appending
# the following to ~/.zshrc:

eval "$(rbenv init -)"

【讨论】:

    【解决方案4】:

    如果你刚刚安装了rvm,你会得到这样的错误

    错误:执行 gem 时 ... (Gem::FilePermissionError) 您没有 /Library/Ruby/Gems/2.6.0 目录的写入权限。

    记得打电话

    source ~/.bash_profile
    

    确保 gem 安装在 ~/.rvm 中

    那你就可以了

    rvm use 2.6.6
    gem install yourgem:2.0.1
    

    【讨论】:

      【解决方案5】:

      在尝试了上述所有不同的解决方案后,没有一个对我有用。因此,对于那些将来会遇到它的人来说,请知道这一点。 该解决方案可能与可可豆荚无关,而与 Xcode 新版本有关。当您更新新版本时,您需要同意新的条款和条件。您可以直接在终端中执行此操作。 跑步 : sudo xcode-select -s /Applications/Xcode.app/Contents/Developer 然后: sudo xcodebuild -license 比按空格键直到你到达按钮最后输入同意 从比可以再次尝试添加 cocoapods 只需: gem 安装 cocoapods

      【讨论】:

        【解决方案6】:

        如果您已安装 rbenv 并遇到此错误,以下答案会有所帮助(这对我来说是这样的)

        问题:

        $ gem install bundler
        ERROR:  While executing gem ... (Gem::FilePermissionError)
            You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
        

        不要使用 SUDO

        1. 检查 rbenv 版本
        $ rbenv versions
        * system (set by /Users/user/.rbenv/version)
          2.3.8
        

        在这里,您可以看到,默认情况下它选择了系统。将其更改为您的 ruby​​ 版本。

        $ rbenv global 2.3.8
        $ rbenv versions
          system
        * 2.3.8 (set by /Users/user/.rbenv/version)
        

        然后尝试安装捆绑器,它将起作用:

        $gem install bundler -v 1.17.3
        Fetching: bundler-1.17.3.gem (100%)
        Successfully installed bundler-1.17.3
        Parsing documentation for bundler-1.17.3
        Installing ri documentation for bundler-1.17.3
        Done installing documentation for bundler after 5 seconds
        1 gem installed
        

        【讨论】:

        • 工作就像一个魅力!
        【解决方案7】:

        我在 Mac 上尝试安装 watchr 包时遇到了类似的问题

        错误:执行 gem 时 ... (Gem::FilePermissionError)

        每次我需要安装一个软件包时都以某种方式运行 sudo 感觉有点过分了。我已经安装了 rbenv,所以我设置了这样的全局 ruby​​ 版本

        rbenv global 2.6.5
        

        然后简单地安装我想要的包。在我的情况下,命令是

        gem install watchr
        

        【讨论】:

          【解决方案8】:

          昨天我尝试使用以下命令安装 rails 时遇到了同样的错误。

          $ gem install rails -v 4.2.3
          

          在此之前我已经安装了 Ruby 环境管理器 (rbenv),但以下命令未能将 if-eval 添加到 bash 配置文件。

          $ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> -/.bash_profile
          

          所以,我对此进行了调查,发现当前目录引用 - 是上述命令失败的问题。我将其更改为 ~ 并成功运行以下命令

          $ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
          

          在此之后,我能够成功安装 rails gem(无需执行 sudo)

          【讨论】:

            【解决方案9】:

            错误:执行 gem 时 ... (Gem::FilePermissionError) 您没有 /Library/Ruby/Gems/2.3.0 目录的写入权限。

            1. 安装 RVM
            2. 在您的 shell 资源文件中设置 gem 文件夹。 IE。 .zshrc.bashrc
            export GEM_HOME="$HOME/.gem"
            
            1. 安装你的 gem gem i LIBRARY_NAME

            【讨论】:

            • 在 MacOsX High Sierra 上为我工作。
            • 对于使用 RVM 的人来说,这是安全使用系统 Ruby 的绝佳解决方案。不要忘记也将$HOME/.gem/bin 添加到您的路径中。
            • stackoverflow.com/a/50361633/574981 使用~/.ruby 这里使用~/.gem 是否有官方或更常见或首选的方式?
            • 我无法安装 LIB,它到底是什么?没有安装 LIB,它运行良好。
            • @StefanKrüger 不知道,但如果谈论 gem,我相信 ~/.gem 文件夹更合适。
            【解决方案10】:

            如果您以 root 用户身份安装了rvm,那么您必须sudo 才能安装任何东西。

            您可以作为普通用户在用户模式下安装rvm,在这种情况下,所有内容都存储在您的主目录中,并且不需要sudo

            如果您不打算进行此特定安装,请输入 sudo rvm implode 并重新开始。

            【讨论】:

            • @IulianOnofrei 这是删除 RVM,而不是安装依赖项。如果是用root安装的,必须用root卸载。
            【解决方案11】:

            您的 global(系统范围)配置文件可能设置了 --no-user-install 标志。创建/编辑您的本地 ~/.gemrc 文件并附加以下行:

            :gemdir:
                - ~/.gem/ruby
            install: --user-install
            

            注意
            gemdir 选项的实际目录将根据您的系统/需求而有所不同;它可能需要也可能不需要,但最好在 home 文件夹 (gemdir) 中指定所需的安装目录,而不是假设它会自行处理。

            ArchLinux Wiki 有一些与此相关的有用/组织良好的信息。


            红宝石

            或者,类似于已经建议的rvm 解决方案,您可以尝试使用chruby 来维护、配置和使用ruby 的本地版本。但是,要安装 ruby 的其他版本,您需要使用 ruby-install

            $ brew install chruby ruby-install
            $ ruby-install ruby 2.4.0
            
            $ echo "source /usr/local/opt/chruby/share/chruby/chruby.sh" >> ~/.bash_profile
            $ echo "chruby ruby" >> ~/.bash_profile
            
            # Do this to select the default alternative ruby installation, assuming
            # there is no other version installed.
            $ chruby ruby
            
            ## Otherwise, list the available ruby versions installed, and select
            $ chruby
            ruby-2.3.0
            ruby-2.4.0
            
            $ chruby ruby-2.4.0
            

            来自项目的自述文件:

            更改当前的 Ruby。特点

            Updates $PATH.
                Also adds RubyGems bin/ directories to $PATH.
            Correctly sets $GEM_HOME and $GEM_PATH.
                Users: gems are installed into ~/.gem/$ruby/$version.
                Root: gems are installed directly into /path/to/$ruby/$gemdir.
            Additionally sets $RUBY_ROOT, $RUBY_ENGINE, $RUBY_VERSION and $GEM_ROOT.
            Optionally sets $RUBYOPT if second argument is given.
            Calls hash -r to clear the command-lookup hash-table.
            Fuzzy matching of Rubies by name.
            Defaults to the system Ruby.
            Optionally supports auto-switching and the .ruby-version file.
            Supports bash and zsh.
            Small (~100 LOC).
            Has tests.
            

            反特征

            Does not hook cd.
            Does not install executable shims.
            Does not require Rubies be installed into your home directory.
            Does not automatically switch Rubies by default.
            Does not require write-access to the Ruby directory in order to install gems.
            

            要求

            bash >= 3 or zsh
            

            【讨论】:

            • 非常感谢! chruby 为我工作,我终于能够在我的 Mac 上再次 gem install bundler 没有这个 Ruby 版本不匹配导致的讨厌的 PermissionDenied-Error !谢谢 :).. 一般来说,您知道在 MacOS 上更新 Ruby 版本是否是个好主意吗?如果是,你更喜欢chruby 还是ruby-install??
            • 您可以使用ruby-install 安装较新版本的ruby。然后,使用chruby 切换到较新的版本。无需为您的项目处理系统范围的 ruby​​ 版本。
            • ~/.gemrc 编辑解决方案对我有用。谢谢!
            【解决方案12】:

            请注意,如果您选择执行 rvm 的多用户安装,则必须通过以下方式将每个用户添加到 rvm 组中

            usermod -a -G rvm <USERNAME>
            

            来自rvm的FAQ的相关信息

            【讨论】:

              【解决方案13】:

              解决错误:

              错误:执行 gem 时 ... (Gem::FilePermissionError) 您没有对 /usr/local/lib/ruby/gems/1.8 目录的写入权限。

              以下解决方案对我有用:

              sudo gem install -n /usr/local/bin cocoapods
              

              【讨论】:

              • 使用 sudo 安装 ruby​​ gem?不确定这是否必要,更不用说智能——在安全性、稳定性等方面。
              • 我不知道为什么这个答案有很多票,最好的做法是永远不要使用 sudo 安装 gem。
              • 只需按照另一个答案 (stackoverflow.com/a/25716203/5362795) 的建议添加 ~/.gemrc 文件,不需要 sudo
              • @Nagev 这为我解决了这个问题。我在 Catalina。
              【解决方案14】:

              假设已安装 rvm,您可以执行以下操作:

              $ rvm install 2.1.1
              $ rvm @global do gem install compass
              

              不需要sudo。

              【讨论】:

                【解决方案15】:

                您可能没有对该路径某处的写入权限(很可能是 /usr/local/lib),您需要更改 RVM 存储的位置以便不需要 sudo

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2021-01-31
                  • 2018-11-16
                  • 2019-08-20
                  相关资源
                  最近更新 更多