Rails: Your user account isn't allowed to install to the system RubyGems

33,560

Solution 1

In my case, I solved doing just what the error message suggests:

Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/

So, instead of:

bundle install

I ran:

bundle install --path vendor/bundle

That was the solution for this guy.

The downside of that solution is that it creates a vendor folder inside the current folder, which can be added to .gitignore if it is to distribute the application through Git.

Solution 2

Usually if you're using RVM, rbenv or chruby to install Ruby, all the gems will be installed in your home folder under ~/.rbenv/ruby-version/...

If you're using your system Ruby though (the one that is installed by default) the gems are installed alongside it in a location that you don't have access to without sudo.

My guess would be that your version manager defaults to the system Ruby but some of your projects have a .ruby-version file in them that tells it to use a different version of Ruby which you have access to.

Solution 3

I had a similar experience. I would have simply ran the code below to fix it temporarily

bundle install --path vendor/bundle

The downside to this is that it does not solve the issue permanently, as the issue will re-surface when you start out with other Ruby on Rails Applications.

I tried this solution, but it did not work for me:

Display a list of all your local gems for the bundler gem

gem list bundler

N/B: The command above is for rbenv version manager, the one for rvm might be different

This will display the versions of the bundler gem installed locally

bundler (2.0.2, default: 1.17.3, 1.10.6)

And then ran the code below below to uninstall version 1.10.6

gem uninstall bundler

Afterwhich I ran the code below to rehash rbenv

rbenv rehash

However, this did not solve the issue.

Here's how I solved it;

The issue was that I mistakenly ran a bundle install operation with administrative rights, that is:

sudo bundle install

which made the owner of the ~/.rbenv OR ~/.rvm directory to become root

To solve the issue I ran the code below to change the ownership of the files and directories.

For rbenv users:

sudo chown -R $USER  ~/.rbenv

And for RVM users

sudo chown -R $USER  ~/.rvm

That's it.

I hope this helps

Solution 4

Good rbenv fix

  • Avoids sudo
  • Avoids install to vendor/bundle

The problem, at least for me, was that bundler itself wasn't installed in my rbenv ruby version. Even though bundler existed and seemed usable... except the permissions error.

One of the things that clued me in was that at the actual command line itself I could install gems ok and not get the error message. I did this for a while as a work-around until I decided to fix the problem permanently as shown below:

To fix it I did:

rbenv local 2.5.0 # Make sure I'm using a local version that exists
gem list | grep bundler # Note no output! Need to fix that!
gem install bundler
rbenv rehash
bundle (within my project that has a Gem file)

Solution 5

  • Open your bashrc or zshrc file.
  • Add eval "$(rbenv init -)"at the end of the file and save it.
  • Run source ~/.zshrc or source ~/.bashrc

You can also close and open the terminal. bundle install and you are good to go.

Share:
33,560
William Entriken
Author by

William Entriken

Lead author of ERC-721. Personal website and contact information: https://phor.net Promoting two open source projects: https://github.com/fulldecent/web-puc - A script to validate you are using the latest JQuery, Bootstrap, Font Awesome versions in your favorite PHP or other web front-end (compatible with Travis CI) https://fulldecent.github.io/cameralife/ - Mature LAMP project for displaying large photo collections on the web (i.e. your life work)

Updated on September 14, 2021

Comments

  • William Entriken
    William Entriken over 2 years

    I am running the command

    bundle install
    

    in a project folder. In some project folders it will produce an error and in other projects folders it will not produce an error. The error is:

    Your user account isn't allowed to install to the system RubyGems

    I know this can be fixed by following the recommended advice:

    bundle install --path vendor/bundle
    

    My question is why is the behavior inconsistent?

  • Antônio Medeiros
    Antônio Medeiros about 6 years
    In the case of a Jekyll static website, also add vendor to the exclude setting in _config.yml. For more information, see: jekyllrb.com/docs/troubleshooting/#configuration-problems
  • ToTenMilan
    ToTenMilan almost 6 years
    On Ubuntu 18.04 from Windows 10 store, you may need to sudo apt update & sudo apt upgrade & sudo apt install gnupg2 before all other commands
  • Prateek Vyas
    Prateek Vyas about 2 years
    hats off to you man!