ruby 错误:执行 gem 时 ... (Gem::FilePermissionError)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18599889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR: While executing gem ... (Gem::FilePermissionError)
提问by Ava
I have checked all the other similar answers and none was exactly like mine, neither did any of those solutions work for me.
我已经检查了所有其他类似的答案,没有一个和我的完全一样,这些解决方案中的任何一个都不适合我。
gem environmentand sudo gem environmentgive the same result:
gem environment并sudo 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
rvm -v: rvm 1.22.3
ruby -v: ruby 1.8.7
ruby -v: ruby 1.8.7
OSX 10.8.4
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
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>gives
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.
whereas I am able to install the same via sudo. What am I doing wrong?
而我可以通过 sudo 安装相同的。我究竟做错了什么?
UPDATE:
更新:
As per comments and this post, I ran following:
根据评论和这篇文章,我运行了以下内容:
rvm implodeand then re installed the stable version.
rvm install 1.9.3or any other ruby installation fails with
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
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:
:
:
:
回答by Amandeep Singh
To resolve the error:
要解决错误:
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /usr/local/lib/ruby/gems/1.8 directory.
错误:执行 gem 时 ... (Gem::FilePermissionError) 您没有对 /usr/local/lib/ruby/gems/1.8 目录的写权限。
the following solution worked for me:
以下解决方案对我有用:
sudo gem install -n /usr/local/bin cocoapods
回答by dimpiax
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
错误:执行 gem 时 ... (Gem::FilePermissionError) 您没有 /Library/Ruby/Gems/2.3.0 目录的写权限。
- Install RVM
- Set the gem folder in your shell resource file. I.e.
.zshrc,.bashrcetc
- 安装 RVM
- 在 shell 资源文件中设置 gem 文件夹。即
.zshrc,.bashrc等
export GEM_HOME="$HOME/.gem"
- Install you gem
gem i LIBRARY_NAME
- 安装你的 gem
gem i LIBRARY_NAME
回答by tadman
If you have installed rvmas the root user, then you must sudoto install anything.
如果您rvm以 root 用户sudo身份安装,那么您必须安装任何东西。
You can install rvmin user-mode as a regular user, in which case everything is stored in your home directory and no sudois required.
您可以rvm作为普通用户在用户模式下安装,在这种情况下,所有内容都存储在您的主目录中,sudo不需要。
If you are not committed to this particular install, type sudo rvm implodeand start over.
如果您不致力于此特定安装,请键入sudo rvm implode并重新开始。
回答by ILMostro_7
Your global(system-wide) config file probably has the --no-user-installflag set. Create/edit your local ~/.gemrcfile and append the following line(s):
您的全局(系统范围)配置文件可能--no-user-install设置了标志。创建/编辑您的本地~/.gemrc文件并附加以下行:
:gemdir:
- ~/.gem/ruby
install: --user-install
Note
The actual directory for the gemdiroption will vary depending on your system/desire; it may or may not be needed, but it's probably better to designate the desired installation directory within your homefolder (gemdir) than to assume it'll be taken care of by itself.
注意
该gemdir选项的实际目录将根据您的系统/需求而有所不同;它可能需要也可能不需要,但最好在您的home文件夹 ( gemdir) 中指定所需的安装目录,而不是假设它会自行处理。
The ArchLinux Wikihas some useful/well-organized information pertaining to this.
该ArchLinux的维基有关于这一些有用/组织良好的信息。
chruby
红宝石
Alternatively, similar to the rvmsolution already suggested, you can try using chrubyto maintain, configure, and use local versions of ruby. To install additional versions of ruby, however, you need to use ruby-install.
或者,类似于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
From the project's README:
来自项目的自述文件:
Changes the current Ruby. Features
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.Anti-Features
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.Requirements
bash >= 3 or zsh
更改当前的 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
回答by Allan
assuming that rvm is installed you could do something like:
假设安装了 rvm,您可以执行以下操作:
$ rvm install 2.1.1
$ rvm @global do gem install compass
No need to do sudo.
无需执行 sudo。
回答by dannymc129
You probably don't have write permissions to somewhere along that path, (most likely /usr/local/lib), you need to change the location of your RVM storage in order to not need sudo
您可能没有对该路径某处的写权限(最有可能是 /usr/local/lib),您需要更改 RVM 存储的位置以便不需要 sudo
回答by Raam
I encountered the same error yesterday when I tried to install rails using following command.
昨天我尝试使用以下命令安装 rails 时遇到了同样的错误。
$ gem install rails -v 4.2.3
Prior to this I had installed Ruby Environment Manager (rbenv), but the following command failed to add the if-eval to bash profile.
在此之前,我已经安装了 Ruby Environment Manager (rbenv),但是以下命令未能将 if-eval 添加到 bash 配置文件中。
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> -/.bash_profile
So, I looked into this and found out that the current directory reference - was the problem for the above command to fail. I changed it to ~ and successfully ran the below command
所以,我调查了这个并发现当前目录引用 - 是上述命令失败的问题。我将其更改为 ~ 并成功运行了以下命令
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
After this I was able to install the rails gem successfully (without needing to do sudo)
在此之后,我能够成功安装 rails gem(无需执行 sudo)
回答by Dmitry
I run into a similar problem on my Mac while trying to install watchr package
我在尝试安装 watchr 包时在 Mac 上遇到了类似的问题
ERROR: While executing gem ... (Gem::FilePermissionError)
错误:执行 gem 时 ... (Gem::FilePermissionError)
Somehow running sudo every time I need to install a package felt excessive. I have rbenv installed so I set global ruby version like this
每次我需要安装软件包时都以某种方式运行 sudo 感觉过度了。我已经安装了 rbenv,所以我设置了这样的全局 ruby 版本
rbenv global 2.6.5
Then simply installed the package I wanted. In my case the command is
然后简单地安装我想要的包。在我的情况下,命令是
gem install watchr

