【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems

时间:2023-03-09 13:33:29
【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems

问题描述

RedisDump 是一个用于 Redis 数据导人/导出的工具,是基于 Ruby 实现的,需要先安装 Ruby。但因为 Mac 自带有 Ruby 所以我直接用gem install redis-dump进行安装,但却出现错误。

【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems

不想更改系统自带的环境,因为后面遇到兼容性问题会很麻烦。于是我重新用 homebrew 装了一个 Ruby ,简单的一句指令即可:

brew install ruby

原以为自己装了新版本 ruby 之后,再执行gem install redis-dump就不会出错了,没想到还是出现刚刚的错误。

解决方法

看了下刚刚装完 ruby 后系统的提示,原来它已经提示我要修改 ~/.bash_profile 了。

【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems

直接在终端输入:

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile

可以看到,这条指令已经在文件的末尾加上了 'export PATH="/usr/local/opt/ruby/bin:$PATH" '

【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems

接着再次输入刚才的 gem 安装命令即可安装成功:

【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems