Pages

Friday, 13 August 2021

Mac上, RubyGems相关的问题

 

安装部分软件提示don’t have write permissions

问题现象

在iMac下面如果使用gem安装部分软件的时候很容易遇到下面的错误:

  temp: sudo gem install --http-proxy http://proxy.com:8080 gollum
Password:

Building native extensions. This could take a while...
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.
%	

原因就是字面意思的原因, gem 要往目录/usr/bin写文件但是权限不够. 因为此时使用的是系统自带的 ruby, 他会在尝试往系统库中安装内容。有时候即使是使用sudo或许也不可以安装。解决这个问题有两种方法:

解决方案

  • 切换用户,使用root尝试或者修改 /Library/Ruby/Gems/XXX 的用户组

  • 重新在别的目录再安装一套ruby

    切换用户方法很简单,使用sudo chown -R即可。不过个人更推荐在安装一个ruby。直接使用homebrew安装后修改环境变量即可。这样我们自定义的和系统的就可以很好的区分开。示例如下:

        blog git:(master)  brew install ruby@2.6
      Updating Homebrew...
      ==> Downloading https://homebrew.bintray.com/bottles/ruby%402.6-2.6.6_1.catalina.bottle.tar.gz
      ==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/b9618a3e2b84a8364e2a9db594c8def107996030155908d1d2f932c97720ef46?response-content-disposition=attach
      ######################################################################## 100.0%
      ==> Pouring ruby@2.6-2.6.6_1.catalina.bottle.tar.gz
      ==> Caveats
      By default, binaries installed by gem will be placed into:
        /usr/local/lib/ruby/gems/2.6.0/bin
    	
      You may want to add this to your PATH.
    	
      ruby@2.6 is keg-only, which means it was not symlinked into /usr/local,
      because this is an alternate version of another formula.
    	
      If you need to have ruby@2.6 first in your PATH run:
        echo 'export PATH="/usr/local/opt/ruby@2.6/bin:$PATH"' >> ~/.zshrc
    	
      For compilers to find ruby@2.6 you may need to set:
        export LDFLAGS="-L/usr/local/opt/ruby@2.6/lib"
        export CPPFLAGS="-I/usr/local/opt/ruby@2.6/include"
    	
      For pkg-config to find ruby@2.6 you may need to set:
        export PKG_CONFIG_PATH="/usr/local/opt/ruby@2.6/lib/pkgconfig"
    	
      ==> Summary
      🍺  /usr/local/Cellar/ruby@2.6/2.6.6_1: 17,226 files, 29.6MB

No comments:

Post a Comment