How do I install RubyGems on my Mac?
如何在Mac上安装RubyGems ?
I tried to run $ gem install rubygems-update
with no luck . It returns
我试着运行$ gem安装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
任何帮助都是好的。谢谢
3 个解决方案
#1
31
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 rbenv and RVM.
IMO go for rbenv:
您可以这样做,但是我建议使用Ruby的环境管理器。有rbenv和RVM。国际海事组织去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
3
You may have to install manually in which case (as per the official website):
您可能需要手动安装在这种情况下(根据官方网站):
- Go to the official website and download the zip file
- 到官方网站下载zip文件
- Unzip the file in a directory.
- 解压目录中的文件。
- Then go to the directory in your terminal and run:
ruby setup.rb
- 然后转到终端中的目录并运行:ruby setup.rb
#3
1
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安装-n /usr/local/bin cocoapods
It perfectly work for me.
这对我来说非常有效。
(I am using macOS Sierra, version 10.12.6)
(我使用的是macOS Sierra,版本10.12.6)
#1
31
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 rbenv and RVM.
IMO go for rbenv:
您可以这样做,但是我建议使用Ruby的环境管理器。有rbenv和RVM。国际海事组织去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
3
You may have to install manually in which case (as per the official website):
您可能需要手动安装在这种情况下(根据官方网站):
- Go to the official website and download the zip file
- 到官方网站下载zip文件
- Unzip the file in a directory.
- 解压目录中的文件。
- Then go to the directory in your terminal and run:
ruby setup.rb
- 然后转到终端中的目录并运行:ruby setup.rb
#3
1
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安装-n /usr/local/bin cocoapods
It perfectly work for me.
这对我来说非常有效。
(I am using macOS Sierra, version 10.12.6)
(我使用的是macOS Sierra,版本10.12.6)