无法将Ruby路径从macOS软件包更改为Homebrew软件包(运行带有英特尔酷睿i7的macOS Monterey)

gc0ot86w  于 2023-05-17  发布在  Ruby
关注(0)|答案(1)|浏览(158)

问题和当前配置摘要

我已经在macOS Monterey上通过Homebrew安装了最新版本的rbenvruby-build(目前运行版本12.6.5,采用英特尔酷睿i7芯片),但是每次我使用ruby -v检查最新的Ruby版本时,我都会收到以下信息:

ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin21]

每当我运行which ruby时,我都会得到以下结果:

/usr/bin/ruby

我检查了我的主目录中的.zsh_profile.zshrc文件,没有看到任何路径表明Ruby/Rbenv被设置为该特定路径。
zsh_profile

# Add NVM
export NVM_DIR=~/.nvm

# Load the shell dotfiles, and then some:
# * ~/.path can be used to extend `$PATH`.
# * ~/.extra can be used for other settings you don’t want to commit.
for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do
    [ -r "$file" ] && [ -f "$file" ] && source "$file";
done;
unset file;

# Case-insensitive globbing (used in pathname expansion)
shopt -s nocaseglob;

# Append to the Bash history file, rather than overwriting it
shopt -s histappend;

# Autocorrect typos in path names when using `cd`
shopt -s cdspell;

# Enable some Bash 4 features when possible:
# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux`
# * Recursive globbing, e.g. `echo **/*.txt`
for option in autocd globstar; do
    shopt -s "$option" 2> /dev/null;
done;

# Add tab completion for many Bash commands
if which brew &> /dev/null && [ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]; then
    # Ensure existing Homebrew v1 completions continue to work
    export BASH_COMPLETION_COMPAT_DIR="$(brew --prefix)/etc/bash_completion.d";
    source "$(brew --prefix)/etc/profile.d/bash_completion.sh";
elif [ -f /etc/bash_completion ]; then
    source /etc/bash_completion;
fi;

# Enable tab completion for `g` by marking it as an alias for `git`
if type _git &> /dev/null; then
    complete -o default -o nospace -F _git g;
fi;

# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | tr ' ' '\n')" scp sftp ssh;

# Add tab completion for `defaults read|write NSGlobalDomain`
# You could just use `-g` instead, but I like being explicit
complete -W "NSGlobalDomain" defaults;

# Add `killall` tab completion for common apps
complete -o "nospace" -W "Contacts Calendar Dock Finder Mail Safari iTunes SystemUIServer Terminal Twitter" killall;test -f ~/.bashrc && source ~/.bashrc
test -f ~/.bashrc && source ~/.bashrc
test -f ~/.bashrc && source ~/.bashrc
test -f ~/.zshrc && source ~/.zshrc
test -f ~/.zshrc && source ~/.zshrc
test -f ~/.zshrc && source ~/.zshrc

if [ -f ~/.zshrc ]; then
    . ~/.zshrc
fi

.zshrc

# Git
function parse_git_branch {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  echo "("${ref#refs/heads/}")"
}
export PS1="\[$(tput bold)\]\w\[$(tput sgr0)\] \$(parse_git_branch)\n$ "
export EDITOR='atom --wait'
export VISUAL='atom --wait'

  export NVM_DIR=~/.nvm
  . $(brew --prefix nvm)/nvm.sh

export HOMEBREW_NO_INSTALL_CLEANUP=TRUE

# Add `~/bin` to the `$PATH`
export PATH="$HOME/.rbenv/bin:$PATH"

# Rbenv
if which rbenv > /dev/null; then
   eval "$(rbenv init -)"
fi

迄今为止为解决问题所采取的步骤

在浏览了一些类似的线程后,似乎这里的问题是macOS默认使用自己的Ruby包,而不是从Homebrew安装的最新包。以下是我迄今为止为解决此问题而采取的步骤,但无济于事:

  • 通过运行brew unlink ruby-buildbrew uninstall rbenvbrew uninstall ruby-build卸载rbenvruby-build
  • 通过运行brew install ruby-buildbrew install rbenvbrew link ruby-build重新安装了rbenvruby-build
  • 通过运行rbenv install '3.2.2'rbenv global '3.2.2'通过rbenv安装最新的ruby版本
  • 通过运行echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc.zshrc文件中设置Ruby路径和源代码
  • 运行brew updatebrew upgrade,没有抛出任何错误
  • 运行brew doctor,也没有抛出任何错误

我还浏览了以下线程,但这些线程中的每个解决方案(其中大部分在上面的步骤中列出)不幸的是,到目前为止还没有为我解决问题:

acruukt9

acruukt91#

2023年5月12日更新:
在进一步研究了macOS Catalina (及更高版本)的bash to zsh文档后,发现我的终端配置的默认路径是/bin/bash,我随后将其配置为/bin/zsh
另外,我运行了以下shell命令:

if [[ $SHELL != '/bin/zsh' ]]; then
  echo "shell was $SHELL" 
  echo 'changing shell to zsh...'
  chsh -s /bin/zsh "$(whoami)"
fi

下面是我得到的ruby版本:

ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin21]

新的道路:

$HOME/.rbenv/shims/ruby

相关问题