gpt4 book ai didi

ruby - 为将来的 gem 安装设置 RVM 以获得正确的权限并正确添加 PATH

转载 作者:数据小太阳 更新时间:2023-10-29 09:00:58 25 4
gpt4 key购买 nike

我已经在互联网上搜索了答案。我觉得我没有按照正确的方式做事,只想以正确的方式设置我的 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"

.个人资料:

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*

最佳答案

首先,停止使用--user-install。 RVM 不需要它,因为这是它的主要目的之一,将 gems 和 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 在命令行中说:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

[...]

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

当您使用默认安装方式安装 RVM 时,它将创建具有正确权限的 ~/.rvm 目录。之后您无需执行任何操作即可让 RVM 和 Ruby 将 gems 存储在该目录中。脚本将能够找到您安装的 gem,而无需使用 gem install 执行任何特殊操作。如果它变得奇怪或困难,那就是有问题了。

关于ruby - 为将来的 gem 安装设置 RVM 以获得正确的权限并正确添加 PATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35828878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com