How do I install ruby gems on Mac

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

How do I install RubyGems on my Mac?

I tried to run $ gem install rubygems-update with no luck . It returns

ERROR:  While executing gem ... (Gem::FilePermissionError)     You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

Any help would be great. Thanks

回答1:

I would highly suggest using a package manager and a Ruby Environment Manager.

On Mac:

brew update brew install ruby  # If you use bash echo 'export PATH=/usr/local/Cellar/ruby/2.4.1_1/bin:$PATH' >> ~/.bash_profile   # If you use ZSH: echo 'export PATH=/usr/local/Cellar/ruby/2.4.1_1/bin:$PATH' >> ~/.zprofile

You can do that but I suggest using an Environment Manager for Ruby. You have rbenv and RVM.
IMO go for rbenv:

brew install rbenv ruby-build  # bash echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile echo 'eval "$(rbenv init -)"' >> ~/.bash_profile    # zsh echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zprofile echo 'eval "$(rbenv init -)"' >> ~/.zprofile    # list all available versions: rbenv install -l  # install a Ruby version: rbenv install 2.4.1  # set ruby version for a specific dir rbenv local 2.4.1  # set ruby version globally rbenv global 2.4.1  rbenv rehash gem update --system


回答2:

You may have to install manually in which case (as per the official website):

  1. Go to the official website and download the zip file
  2. Unzip the file in a directory.
  3. Then go to the directory in your terminal and run: ruby setup.rb


回答3:

It is showing that you don't have the permission to write something in that directory. Instead use this directory :

sudo gem install -n /usr/local/bin cocoapods

It perfectly work for me.

(I am using macOS Sierra, version 10.12.6)



转载请标明出处:How do I install ruby gems on Mac
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!