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

79

我查看了所有类似的答案,但没有一个完全符合我的情况,也没有任何一种解决方案对我有效。

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 -vrvm 1.22.3

ruby -vruby 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安装相同的软件,但为什么不能直接安装?我做错了什么吗?

更新:

根据评论和这篇文章,我运行了以下命令:

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 应该可以解决这个问题。 - Lavixu
rvm列表ext-ree-1.8.7-2011.12所使用的ruby是/usr/local/bin/ruby - Ava
尝试执行以下命令: rvm remove ext-ree-1.8.7-2011.12 . rvm install 1.8.2 . 然后使用 rvm use '新安装的Ruby版本' --default 设置默认Ruby版本。 - Lavixu
rvm install 1.8.2 失败,并出现以下错误提示:http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.2.tar.gzruby-1.8.2.tar.gz 没有校验和,因此无法验证。 - Ava
我只是在遵循上面的评论。我想安装1.8.7,但是遇到了更新答案中提到的错误。 - Ava
显示剩余2条评论
19个回答

0

问题: sudo

我正在使用asdf版本管理器。我尝试为Flutter安装。最初,我已经使用sudo安装了gem包,然后我在文档中读到应该为版本管理器安装而不使用sudo,所以我尝试卸载它,然后重新安装而不使用sudo,但是出现了以下错误:

╰─❯ gem install cocoapods                                                                  
Successfully installed cocoapods-1.11.3
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Users/coder/.asdf/installs/ruby/3.1.0-dev/lib/ruby/gems/3.2.0+0/doc/cocoapods-1.11.3 directory.

解决方法

我进入了上述目录并删除了空文件夹。

然后我成功运行了gem install cocoapods,没有出现任何错误。

不幸的是,flutter doctor仍然似乎对cocoapods的可用性感到不满意。

flutter doctor的解决方法

看起来它不喜欢Ruby v3.2,这很奇怪,因为asdf显示我有v3.1,这让人困惑。我决定安装Ruby v2.7.4,然后只需运行gem install cocoapods,现在flutter doctor全部绿色通过。


0
作为Mac用户,以下内容很简单。
❯ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
❯ brew install ruby

选项(1)如果您正在使用zhs,则添加路径

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
❯ source ~/.zshrc

选项(2)如果您正在使用bash,则添加路径

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
❯ source ~/.bash_profile

0
请注意,如果您选择执行rvm的多用户安装,则必须通过以下方式将每个用户添加到rvm组:
usermod -a -G rvm <USERNAME>

来自rvm的相关信息常见问题解答


0

好的,在尝试了上面所有不同的解决方案后,它们都对我没有用。所以对于将来会遇到这个问题的人,请知道这一点。 解决方案可能与CocoaPods无关,而更多地涉及Xcode的新版本。当您更新新版本时,您需要同意新的条款和条件。您可以直接在终端中执行此操作。 运行: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer 然后: sudo xcodebuild -license 然后按空格键直到您到达按钮,最后键入agree 从那时起,您可以再次尝试使用以下命令添加CocoaPods: gem install cocoapods


0

这取决于上下文。 例如,如果您从Jenkins角度运行此操作,事情的工作方式与启动bash shell并提供gem或bundle指令时不同。我在Jenkins中遇到了相同的错误,但未能意识到Jenkins有自己的解决PATH问题的方式,因此在那里可能无法正常工作,除非您找到适当的Jenkins配置字段来填写相关信息,例如Ruby所在的位置。否则,您可能会发出符号链接命令以将机器理解可执行文件的位置链接起来。


0

我尝试使用brew ruby install更新我的ruby到最新版本

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


你能更清楚地解释一下吗? - Chiara Ani

0

昨天我尝试使用以下命令安装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命令)。


0

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

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

每次需要安装软件包时都要运行sudo感觉有些过度。我已经安装了rbenv,所以我像这样设置了全局ruby版本。

rbenv global 2.6.5

然后我只需安装我想要的软件包。在我的情况下,命令是

gem install watchr

-1

你可能没有沿着那个路径的写入权限(最有可能是 /usr/local/lib),你需要改变 RVM 存储的位置,以便不需要使用 sudo。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接