In my case the above suggestions did not work for me. Mine was little different scenario.
When i tried installing bundler
using gem install bundler
.. But i was getting
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
then i tried using sudo gem install bundler
then i was getting
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
then i tried with sudo gem install bundler -n /usr/local/bin
( Just /usr/bin
dint work in my case ).
And then successfully installed bundler
EDIT: I use MacOS, maybe /usr/bin
din't work for me for that reason (https://stackoverflow.com/a/34989655/3786657 comment )