Bundler Cannot Install Any Gems Without Sudo

How to install gems without sudo on Mac OS X

If you can't use gem without sudo, it sounds like you haven't initialized rbenv correctly because the shims aren't available.

These steps are from the documentation. Confirm you did them ALL:

Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile.

Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.

Add rbenv init to your shell to enable shims and autocompletion.

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

Same as in previous step, use ~/.bashrc on Ubuntu, or ~/.zshrc for Zsh.

Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if rbenv was set up:

$ type rbenv
#=> "rbenv is a function"

How to install ruby gem without sudo?

You have only enable very old (and not maintained) remote gem sources in your gem configuration. This might be caused by some old migrated configuration or by following some very old and outdated advice.

To fix this, you first need to remove the outdated gem sources and then add the only one which should be currently used. For that, you can run the following command from your Terminal:

gem sources --remove http://gems.github.com/
gem sources --remove http://gems.rubyforge.org/

gem sources --add https://rubygems.org/

How to fix sudo bundle install

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

Install bundler on MacOS with out using sudo?

I'm a Jekyll user as well. But, I didn't run into this issue. I believe it's because I use rbenv to manage Ruby, and installed 2.5.3 with it first.

I'd highly recommend checking out rbenv. While I do find managing Ruby to be kind of a pain to setup, once you have things set, it works quite well.

One you have a dedicated, non-system-installed Ruby, you won't need sudo. From there, you can also use bundle install --path vendor/bundle to really contain your gems into your current project.

Good luck, and hopefully this is helpful.

How to make bundler work again for non root users ? (after mistakenly using it with root)

You should try changing the owner and setting the correct permissions for your ~/.bundle.

Try:

sudo chown -R <youruser> ~/.bundle

Followed by:

sudo chmod -R 655 ~/.bundle

How can I fix an accidental 'sudo bundle install dir_name'?

After a bit of Googling around i was able to find the answer
Just run:

sudo bundle install --system and you'll have your gems back at their appropriate system directories.



Related Topics



Leave a reply



Submit