我已经在网上搜索了答案。我觉得我没有按照正确的方式做事,只是想以正确的方式建立我的rvm环境。这一切都源于我不得不使用sudo gem install sass
安装SASS,我不想这样做。
现在当我gem install sass
时,我得到了:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
我采取的步骤:
sudo chown -R dhruv: /Library/Ruby/Gems/2.0.0
\curl -sSL https://get.rvm.io | bash -s stable --ruby
brew install gnupg gnupg2
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
sudo chown -R dhruv:staff ~/.rvm
sudo chown -R dhruv:staff ~/.gem
sudo chown -R dhruv:staff /Library/Ruby/Gems/2.0.0
请注意which rvm
没有返回任何内容,即使上面运行curl命令也给了我:
Upgrading the RVM installation in /Users/dhruv/.rvm/
RVM PATH line found in /Users/dhruv/.mkshrc /Users/dhruv/.profile /Users/dhruv/.bashrc /Users/dhruv/.zshrc.
RVM sourcing line found in /Users/dhruv/.profile /Users/dhruv/.bash_profile /Users/dhruv/.zlogin.
Upgrade of RVM in /Users/dhruv/.rvm/ is complete.
# dhruvghulati,
#
# Thank you for using RVM!
# We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.
我想把事情变成一个我可以在没有sudo的情况下轻松安装gems的状态。我该怎么做?
另外,如何防止rvm
看到的这些PATH错误?
我担心当我sudo chown -R dhruv:staff /Library/Ruby/Gems/2.0.0
时,互联网似乎说这是一个可怕的邪恶,我将不得不回复?我是否可以将chmod
还原为原始用户,该用户应该归?
以下是rvm info
的输出:
Warning! PATH is not properly set up, '/Users/dhruv/.rvm/gems/ruby-2.2.1/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.2.1'.
ruby-2.2.1:
system:
uname: "Darwin Dhruvs-MacBook-Pro-2.local 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep 1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64"
system: "osx/10.10/x86_64"
bash: "/bin/bash => GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)"
zsh: "/bin/zsh => zsh 5.0.5 (x86_64-apple-darwin14.0)"
rvm:
version: "rvm 1.26.11 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
updated: "1 day 8 minutes 30 seconds ago"
path: "/Users/dhruv/.rvm"
ruby:
interpreter: "ruby"
version: "2.2.1p85"
date: "2015-02-26"
platform: "x86_64-darwin14"
patchlevel: "2015-02-26 revision 49769"
full_version: "ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]"
homes:
gem: "/Users/dhruv/.rvm/gems/ruby-2.2.1"
ruby: "/Users/dhruv/.rvm/rubies/ruby-2.2.1"
binaries:
ruby: "/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin/ruby"
irb: "/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin/irb"
gem: "/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin/gem"
rake: "/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin/rake"
environment:
PATH: "/Users/dhruv/anaconda/bin:/Users/dhruv/anaconda/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin:/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib"
GEM_HOME: "/Users/dhruv/.rvm/gems/ruby-2.2.1"
GEM_PATH: "/Users/dhruv/.rvm/gems/ruby-2.2.1:/Users/dhruv/.rvm/gems/ruby-2.2.1@global"
MY_RUBY_HOME: "/Users/dhruv/.rvm/rubies/ruby-2.2.1"
IRBRC: "/Users/dhruv/.rvm/rubies/ruby-2.2.1/.irbrc"
RUBYOPT: ""
gemset: ""
命令gem install --user-install sass
给了我:
WARNING: You don't have /Users/dhruv/.gem/ruby/2.2.0/bin in your PATH,
gem executables will not run.
Successfully installed sass-3.4.21
Parsing documentation for sass-3.4.21
Done installing documentation for sass after 4 seconds
1 gem installed
的.bash_profile:
export PATH=$PATH:~/.gem/ruby/2.0.0/bin
export SBT_OPTS="-Xmx2G -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=2G -Xss2M -Duser.timezone=GMT"
export PATH=$PATH:~/scripts
source ~/.profile
source ~/.bashrc
export PATH=$PATH:/usr/local/lib
# added by Anaconda3 2.3.0 installer
export PATH="/Users/dhruv/anaconda/bin:$PATH"
export MONGO_PATH=/usr/local
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
.bashrc中:
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
.profile中:
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
答案 0 :(得分:2)
首先,停止使用--user-install
。您不应该将它与RVM一起使用,因为这是其主要目的之一,将gem和Ruby保留在您的主目录中。
你的道路建设不好:
"/Users/dhruv/anaconda/bin:/Users/dhruv/anaconda/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin:/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib"
分解为:
/Users/dhruv/anaconda/bin
/Users/dhruv/anaconda/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin
/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
/Users/dhruv/.gem/ruby/2.0.0/bin
/Users/dhruv/scripts
/Users/dhruv/.rvm/bin
/Users/dhruv/.rvm/bin
/usr/local/lib
/Users/dhruv/.gem/ruby/2.0.0/bin
/Users/dhruv/scripts
/Users/dhruv/.rvm/bin
/Users/dhruv/.rvm/bin
/usr/local/lib
你需要在路径中首先使用RVM,但是你正在阻碍它。
它应该类似于:
/Users/dhruv/.rvm/gems/ruby-2.2.1/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin
/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin
/Users/dhruv/scripts
/Users/dhruv/anaconda/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
我将〜/ .bash_profile重写为:
source ~/.bashrc
export MONGO_PATH=/usr/local
export SBT_OPTS="-Xmx2G -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=2G -Xss2M -Duser.timezone=GMT"
export PATH=~/scripts:~/anaconda/bin:$PATH
# RVM needs to initialize last so it can adjust the path correctly...
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
我将〜/ .bashrc重写为:
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
我将〜/ .profile重写为:
# export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
那应该清理你的路径,并且可能会让RVM更好地解决问题。
您可能需要进行次要调整,但要保持简单。
我建议阅读shell如何使用PATH查找内容以及如何定义PATH。另外,阅读有关使用〜/ .bashrc,〜/ .profile和〜/ .bash_profile的信息会很好,特别是在Mac OS上。命令行中的man bash
除其他外说:
当bash作为交互式登录shell调用,或作为带有--login选项的非交互式shell调用时,它首先从文件/ etc / profile中读取并执行命令,如果 该文件存在。读取该文件后,它按顺序查找〜/ .bash_profile,〜/ .bash_login和〜/ .profile,并从第一个文件中读取并执行命令 存在且可读。启动shell以禁止此行为时,可以使用--noprofile选项。
[...]
当启动不是登录shell的交互式shell时,bash会读取并执行来自〜/ .bashrc的命令(如果该文件存在)。这可以通过使用来抑制 --norc选项。 --rcfile文件选项将强制bash从文件而不是〜/ .bashrc读取和执行命令。
使用默认安装安装RVM时,它将使用正确的权限创建~/.rvm
目录。在此之后,您不必做任何事情让RVM和Ruby在该目录中存储宝石。脚本将能够找到您已安装的宝石而无需对gem install
做任何特殊操作。如果它变得奇怪或困难,那就是错误的。
答案 1 :(得分:0)
您可以使用以下命令在本地用户目录中安装:
gem install --user-install <gemname>
别名gem install
到gem install --user-install
,以避免将来输入。
另外,尝试运行rvm gemdir
以查找将安装gem的位置。
如果没有别的,请尝试运行rvm reinstall
。