如何在 Mac 上安装 ruby gems
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39381360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I install ruby gems on Mac
提问by Lex B
How do I install RubyGems on my Mac?
如何在 Mac 上安装 RubyGems?
I tried to run $ gem install rubygems-updatewith no luck . It returns
我试图跑$ gem install rubygems-update,但没有走运。它返回
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
任何帮助都会很棒。谢谢
回答by melMass
I would highly suggest using a package manager and a Ruby Environment Manager.
我强烈建议使用包管理器和 Ruby 环境管理器。
On Mac:
在 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 rbenvand RVM.
IMO go for rbenv:
您可以这样做,但我建议使用 Ruby 环境管理器。你有rbenv和RVM。
IMO 选择 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
回答by Olleg
One more variant is to use brew-gem.
另一种变体是使用 brew-gem。
https://formulae.brew.sh/formula/brew-gem
https://formulae.brew.sh/formula/brew-gem
https://github.com/sportngin/brew-gem
https://github.com/sportngin/brew-gem
Just copy/paste from the documentation:
只需从文档中复制/粘贴:
brew install brew-gem
Usage
brew gem install herokuTo install a specific version:
brew gem install heroku 3.8.3To install using a brew installed ruby(/usr/local/bin/ruby):
brew gem install heroku --homebrew-rubyAnd with a specific version:
brew gem install heroku 3.8.3 --homebrew-rubyTo upgrade:
brew gem upgrade herokuTo uninstall:
brew gem uninstall herokuTo check information:
brew gem info herokuNote: Installed gems are listed in brew list with prefix of gem-, like gem-heroku.
酿造安装酿造宝石
用法
brew gem install heroku要安装特定版本:
brew gem install heroku 3.8.3要使用 brew 安装的 ruby(/usr/local/bin/ruby) 进行安装:
brew gem install heroku --homebrew-ruby并使用特定版本:
brew gem install heroku 3.8.3 --homebrew-ruby升级:
brew gem upgrade heroku卸载:
brew gem uninstall heroku检查信息:
brew gem info heroku注意:已安装的 gem 列在 brew 列表中,前缀为gem-,例如gem-heroku。
回答by Sagar Pandya
You may have to install manually in which case (as per the official website):
在这种情况下,您可能需要手动安装(根据官方网站):
- Go to the official websiteand download the zip file
- Unzip the file in a directory.
- Then go to the directory in your terminal and run:
ruby setup.rb
- 前往官方网站下载的zip文件
- 将文件解压缩到一个目录中。
- 然后转到终端中的目录并运行:
ruby setup.rb
回答by mrjamesmyers
After installing cocoapods as Tulon suggested the thing which worked for me was passing the --user-installflag to the gem install command e.g
在安装 cocoapods 后,因为 Tulon 建议对我有用的东西是将--user-install标志传递给 gem install 命令,例如
gem install rubygems-update --user-install
gem install rubygems-update --user-install
from https://guides.cocoapods.org/using/getting-started.html#sudo-less-installation
来自https://guides.cocoapods.org/using/getting-started.html#sudo-less-installation
回答by Tulon
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
sudo gem install -n /usr/local/bin cocoapods
It perfectly work for me.
它非常适合我。
(I am using macOS Sierra, version 10.12.6)
(我使用的是 macOS Sierra,版本 10.12.6)

