[英]How to reset anything related to Ruby to factory settings on Mac OS High Sierra
After a number of misadventures involving RVM, Ruby and Rails on my new laptop have left me completely bewildered.在我的新笔记本电脑上涉及 RVM、Ruby 和 Rails 的许多不幸事件之后,我完全不知所措。 I uninstalled RVM but all the paths, versions and permissions are all messed up.
我卸载了 RVM,但所有路径、版本和权限都乱七八糟。
I searched and couldn't find the right fixes.我进行了搜索,但找不到正确的修复方法。 It feels like each solution makes the problem get worse.
感觉每个解决方案都会使问题变得更糟。
I want to start fresh without having to reset my computer to factory settings.我想重新开始,而不必将计算机重置为出厂设置。 How can I reset just the Ruby-related things like Ruby, Rails, etc., without erasing my computer?
我怎样才能只重置与 Ruby、Rails 等 Ruby 相关的东西,而不清除我的计算机?
I would close & reopen your terminal window before you start all of this to make sure you don't have any old env vars loaded.在你开始所有这些之前,我会关闭并重新打开你的终端窗口,以确保你没有加载任何旧的环境变量。
General things:一般的东西:
env | grep RUBY
env | grep RUBY
env | grep RUBY
, env | grep RVM
env | grep RUBY
, env | grep RVM
env | grep RVM
and look for any leftover environment variables that you may have set env | grep RVM
并查找您可能已设置的任何剩余环境变量env | grep GEM
env | grep GEM
env | grep GEM
. env | grep GEM
。 Sometimes you'll see GEM_PATH
, GEM_HOME
, etc. but these aren't necessary for system rubyGEM_PATH
、 GEM_HOME
等,但这些对于系统 ruby 不是必需的~/.bash_profile
, ~/.bashrc
, and ~/.profile
files and see if you've added any rvm stuff~/.bash_profile
、 ~/.bashrc
和~/.profile
文件,看看你是否添加了任何 rvm 东西If you're running macOS Mojave (I'm comparing against my system):如果您运行的是 macOS Mojave(我正在与我的系统进行比较):
which ruby
should return /usr/bin/ruby
. which ruby
应该返回/usr/bin/ruby
。 If it doesn't, you have something else interfering.如果没有,则说明您有其他干扰因素。 Post what that is and we can get it fixed.
发布那是什么,我们可以解决它。
Running /usr/bin/ruby --version
should return ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
运行
/usr/bin/ruby --version
应该返回ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
Permissions for system ruby:系统红宝石的权限:
-r-xr-xr-x 1 root wheel 52016 Nov 30 02:38 /usr/bin/ruby
This should be something like sudo chmod 555 /usr/bin/ruby
to fix this if yours is difference.如果您的不同,这应该类似于
sudo chmod 555 /usr/bin/ruby
来解决这个问题。 If you have different owners you'll need to sudo chown root:wheel /usr/bin/ruby
如果你有不同的所有者,你需要
sudo chown root:wheel /usr/bin/ruby
You'll also want to check which gem
, and see if it reports /usr/bin/gem
.您还需要检查
which gem
,看看它是否报告/usr/bin/gem
。 Permissions should be the same as /usr/bin/ruby
.权限应与
/usr/bin/ruby
相同。 /usr/bin/gem --version
should return 2.5.2.3
/usr/bin/gem --version
应该返回2.5.2.3
Running /usr/bin/gem env
should return something similar-ish to below.运行
/usr/bin/gem env
应该返回类似于下面的内容。 Replace jay
(my computer user) with yours用你的替换
jay
(我的电脑用户)
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.2.3
- RUBY VERSION: 2.3.7 (2018-03-28 patchlevel 456) [universal.x86_64-darwin18]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.3.0
- USER INSTALLATION DIRECTORY: /Users/jay/.gem/ruby/2.3.0 # this doesn't matter much
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /Users/jay/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-18
- GEM PATHS:
- /Library/Ruby/Gems/2.3.0
- /Users/jay/.gem/ruby/2.3.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0
- GEM CONFIGURATION:
- :update_sources => false
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["https://rubygems.org/"]
- "benchmark" => true
- "gem" => "--document=yri"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /Users/jay/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /opt/X11/bin
From there you've got two directories you probably want to look at:从那里你有两个你可能想要查看的目录:
Run ls -al /Library/Ruby/
.运行
ls -al /Library/Ruby/
。 You should see this:你应该看到这个:
drwxr-xr-x 3 root wheel 96 Aug 17 18:59 Gems
drwxr-xr-x 3 root wheel 96 Aug 17 18:59 Site
You may need to chmod/chown each of those directories (with -R
for recursive)您可能需要 chmod/chown 每个目录(使用
-R
递归)
When you're done, please note that running /usr/bin/gem install bundler
and gem install bundler
(assuming you haven't installed a new ruby version manager) should yield an error as below (this means you re-configured the permissions correctly).完成后,请注意运行
/usr/bin/gem install bundler
和gem install bundler
(假设您还没有安装新的 ruby 版本管理器)应该会产生如下错误(这意味着您重新配置了权限正确)。
Fetching: bundler-1.17.2.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
You'll see some tutorials mention changing those permissions, or running sudo to install gems but I don't recommend that.您会看到一些教程提到更改这些权限,或运行 sudo 来安装 gems,但我不建议这样做。 My favorite ruby version manager is asdf which may be worth a look.
我最喜欢的 ruby 版本管理器是asdf ,它可能值得一看。 You'll install the core, and the ruby plugin .
您将安装核心和ruby 插件。
This should get you a little bit closer.这应该让你更接近一点。 If you see anything else messed up, please post the error.
如果您看到任何其他问题,请发布错误。
rm -rf ~/.rvm
, then edit ~/.bash_profile
to remove source $HOME/.rvm/scripts/rvm
. rm -rf ~/.rvm
,然后编辑~/.bash_profile
以删除source $HOME/.rvm/scripts/rvm
。
Then you can restart with RVM from scratch by following the detailed installation instructions at https://rvm.io/rvm/install .然后,您可以按照https://rvm.io/rvm/install上的详细安装说明从头开始使用 RVM 重新启动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.