William Entriken
William Entriken

Reputation: 39283

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

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?

Upvotes: 35

Views: 44493

Answers (9)

Promise Preston
Promise Preston

Reputation: 28940

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

Upvotes: 17

If you are using rbenv, all you need to do is provide a .ruby-version file.

Upvotes: 0

Bhudeb Kr Sarkar
Bhudeb Kr Sarkar

Reputation: 31

  • 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.

Upvotes: 3

ToTenMilan
ToTenMilan

Reputation: 640

Using RVM:

You have to install rvm for your single user (standard user / non root user), in your $HOME directory (It's not installed if you don't have /home/youruser/.rvm directory.

As is specified on rvm site under "Single-User Install Location: ~/.rvm/" section, to install rvm for single user run:

cd
\curl -sSL https://get.rvm.io | bash -s -- --ignore-dotfiles

Now, rvm should be installed. As in further prompt, refresh rvm (with your username provided):

source /home/---YOURUSERNAME---/.rvm/scripts/rvm

To prevent prompts for installing sudo-need packages, run:

rvm autolibs disable

You can install Ruby for your user only, in version 2.5 (or any other, listed in rvm list known)

rvm install 2.5

Explanation:

You probably try to install rvm using sudo and maybe with this package for ubuntu but you don't have sudo permissions.

This prompt is telling you that you can't bundle gems globally for the whole system, which may be good for your private home machine but not for your corporate user(machine), which is often administered by someone else.

If rvm will be installed in your $HOME gems will be bundled there, like usual.

Behavior may be inconsistent because other users have rvm installed in their $HOME directory

Upvotes: 4

Oleh  Sobchuk
Oleh Sobchuk

Reputation: 3722

Recently faced the same issue. I use rvm

sudo chown -R $USER ~/.rvm helped for me

Upvotes: 1

Michael Durrant
Michael Durrant

Reputation: 96484

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)

Upvotes: 7

Antônio Medeiros
Antônio Medeiros

Reputation: 3268

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.

Upvotes: 36

pocheptsov
pocheptsov

Reputation: 1956

In my case, I had an existing $BUNDLE_PATH without enough permissions to the bundler user to write in.

Your user account isn't allowed to install to the system RubyGems
bundle install --path vendor/bundle

Upvotes: 2

isaacsloan
isaacsloan

Reputation: 885

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.

Upvotes: 15

Related Questions