问题总结和当前配置
我已经在 macOS Monterey 上通过 Homebrew 安装了最新版本的
rbenv
和 ruby-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 安装的最新包。以下是我迄今为止为尝试解决此问题而采取的步骤,但无济于事:
rbenv
、ruby-build
和brew unlink ruby-build
卸载
brew uninstall rbenv
和
brew uninstall ruby-build
rbenv
、ruby-build
和brew install ruby-build
重新安装
brew install rbenv
和
brew link ruby-build
rbenv install '3.2.2'
和 rbenv global '3.2.2'
.zshrc
在
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
brew update
和brew upgrade
,没有抛出任何错误brew doctor
,也没有抛出任何错误我也浏览了以下线程,但不幸的是,这些线程中的每个解决方案(其中大部分已在上面的步骤中列出)都没有解决我的问题: