【英文】MacOS通过gem安装软件时报错

Preface

Error occurred when installing software via gem in MacOS: ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

Cause

  • MacOS’s built-in Ruby requires access to system directories, which has insufficient permissions.

Solution

  • In order to keep the built-in Ruby in MacOS without affecting Ruby development, you can install an additional Ruby.
1
brew install ruby

Version of built-in Ruby in MacOS

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

Version of Ruby installed via brew

1
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/ruby -v
1
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin21]

Installing Software Packages

  • Use the gem installed via brew to install software packages

3.2.2_1: Version of Ruby installed via brew
<name>: Name of the software package

1
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/gem install <name>

Location of Software Packages

  • Software installed via gem installed via brew may be stored in the directory at the same level as gem.

In this case, sass was installed using gem installed via brew.

1
/opt/homebrew/Cellar/ruby/3.2.2_1/bin/sass
  • It may also be located in the lib directory.
1
/opt/homebrew/lib/ruby/gems/3.2.0/bin/sass

Completion

References

CSDN - Mr.时光流年
CSDN - sepier