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.
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.
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.
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.
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
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
sudo gem install -n /usr/local/bin bundler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With