Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install ruby gems on Mac

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

like image 255
Lex B Avatar asked Sep 08 '16 01:09

Lex B


People also ask

Where are RubyGems installed Mac?

By default, binaries installed by gem will be placed into: /usr/local/lib/ruby/gems/3.1.

Where do I put RubyGems?

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/. gem/ruby/1.9. 1 . The commands provided by the gems you installed will end up in ~/.

What is RubyGems on Mac?

RubyGems is a package management framework for Ruby. Download the latest version here: tgz zip gem git. Or, to upgrade to the latest RubyGems: $ gem update --system.


2 Answers

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 
like image 111
melMass Avatar answered Oct 02 '22 03:10

melMass


One more variant is to use brew-gem.

https://formulae.brew.sh/formula/brew-gem

https://github.com/sportngin/brew-gem

Just copy/paste from the documentation:

brew install brew-gem

Usage

brew gem install heroku

To install a specific version: brew gem install heroku 3.8.3

To install using a brew installed ruby(/usr/local/bin/ruby): brew gem install heroku --homebrew-ruby

And with a specific version: brew gem install heroku 3.8.3 --homebrew-ruby

To upgrade: brew gem upgrade heroku

To uninstall: brew gem uninstall heroku

To check information: brew gem info heroku

Note: Installed gems are listed in brew list with prefix of gem-, like gem-heroku.

like image 44
Olleg Avatar answered Oct 02 '22 02:10

Olleg