Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory

When I use command gem install bundler in MacOS 10.13.x, the error is:

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

$ gem install bundler
Fetching: bundler-1.16.2.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
like image 281
Chars Davy Avatar asked Aug 03 '18 03:08

Chars Davy


People also ask

How do I install gem bundler?

Install BundlerSelect Tools | Bundler | Install Bundler from the main menu. Press Ctrl twice and execute the gem install bundler command in the invoked popup. Open the RubyMine terminal emulator and execute the gem install bundler command.

How do I know what version of Ruby I have Mac?

Don't type the $ character – the $ character is just a cue that you should enter a shell command. The ruby -v command will show you the Ruby version number.

How do I update Ruby on my Mac?

If you're using Ruby on a Mac, it is set up by default, but you can't modify or upgrade it. Most developers don't use the pre-installed version of Ruby on their Macs.


3 Answers

This is basically a duplicate of this question, where I already posted a detailed answer that solves the problem. Instead of maintaining two separate answers, I thought it would be better to just link to my answer here since the same solution applies: https://stackoverflow.com/a/54873916/928191

like image 187
monfresh Avatar answered Sep 24 '22 23:09

monfresh


As previously noted, on a Mac the system ruby is owned by root and it's not safe to install things against that version with sudo. If you do every gem runs as root and that's a security nightmare. DO NOT DO THAT

I'll walk you through my steps since previous answers assume a bit of command line foo and the added details might be of some use to someone.

Double-check we're running the old, system provided ruby

which ruby
/usr/bin/ruby

(that's the system path)

ruby -v
ruby 2.3.7

(the old version)

brew install ruby

or install brew first

at the end of which, the install says:

/usr/local/Cellar/ruby/2.6.3

Make that show up in the path first

PATH=/usr/local/Cellar/ruby/2.6.3/bin:$PATH

Double-check

which ruby
/usr/local/Cellar/ruby/2.6.3/bin/ruby

Double-check version

ruby --version
ruby 2.6.3p62

Make the path update permanent (otherwise you'll have to update the path each time you want to use ruby)

echo  PATH=/usr/local/Cellar/ruby/2.6.3/bin:$PATH >> ~/.bash_profile
like image 39
joar Avatar answered Sep 23 '22 23:09

joar


sudo gem install -n /usr/local/bin bundler
like image 42
Chars Davy Avatar answered Sep 26 '22 23:09

Chars Davy