前言
最近使用sudo gem install slather
安装slather
失败,怀疑是ruby
版本问题,因此升级ruby
版本。
安装slather发生错误
gem install slather
报错信息:
ERROR: Error installing slather:
ERROR: Failed to build gem native extension.
...省略一大堆信息...
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/racc-1.5.2 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/racc-1.5.2/gem_make.out
或者:
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:229: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
需要更新ruby。
查看当前ruby版本
查ruby版本命令行:
ruby -v
这是Mac自带的ruby版本:
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
安装ruby最新版本
命令行
brew install ruby
安装完成后,执行ruby -v
还是显示原来的版本,这是因为环境变量没有配置。
将ruby环境变量配置到~/.zshrc
中:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
使其立即生效:
source ~/.zshrc
现在执行:
ruby -v
显示已是新版本:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
网友评论