How to run “bundle install” as root

The “bundle install” command does not allow you to run it as root. For example, the following sequence of commands will fail:

gem update --system
xcode-select --install
gem install nokogiri
bundle install

The last command will show an error:

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Could not locate Gemfile

This can be a real problem if the primary user on your computer is root. On some servers, the default user is root.

bundle install” has no options to ignore the command being run with elevated privileges. But there is still a way to get around this problem – create a new user and execute the command on his behalf.

To create a new user in Debian, Kali Linux, Linux Mint, Ubuntu, run a command like this:

sudo useradd -m -G sudo -s /bin/bash NEW_USER

To create a new user in Arch Linux, Manjaro, BlackArch and their derivatives, run a command like:

sudo useradd -m -g users -G wheel,video -s /bin/bash NEW_USER

After that, it is enough to sign in as a new user:


And run bundle again:

bundle install

This time the command will end successfully.

To return to the root user, that is, log out of the new user session, press Ctrl+d.

Leave Your Observation

Your email address will not be published. Required fields are marked *

Scroll Up