From Bundler's documentation:
By default, Bundler installs gems to the same location as gem install.
In some cases, that location may not be writable by your Unix user. In that case, >Bundler will stage everything in a temporary directory, then ask you for your >sudo password in order to copy the gems into their system location.
From your perspective, this is identical to installing the gems directly into the >system.
You should never use sudo bundle install. This is because several other steps in >bundle install must be performed as the current user:
Updating your Gemfile.lock
Updating your vendor/cache, if necessary
Checking out private git repositories using your user's SSH keys
Of these three, the first two could theoretically be performed by chowning the >resulting files to $SUDO_USER. The third, however, can only be performed by >invoking the git command as the current user. Therefore, git gems are downloaded >and installed into ~/.bundle rather than $GEM_HOME or $BUNDLE_PATH.
As a result, you should run bundle install as the current user, and Bundler will >ask for your password if it is needed to put the gems into their final location.
As a possible solution you can fully uninstall Ruby and its dependencies, and then install Ruby using asdf, RVM or rbenv and run Bundler again.
I use Bundler just to install gems from a gemfile. cd
into the project with the gemfile and run bundle install
. It must find the gemfile and install the gems automatically. I think it's bad to use Bundler inside the home directory.
I have all gems installed here:
~/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems