How to run “bundle install” as root
February 20, 2021
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:
su - NEW_USER
And run bundle again:
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.
- Error “ruby-bundler: /usr/share/man/man5/gemfile.5.gz exists in filesystem (owned by ruby)” (SOLVED) (100%)
- How to convert a string to uppercase in Bash (97.2%)
- How to convert a string to lowercase in Bash (97.2%)
- Analogue of the --force option in pacman (52.8%)
- How to downgrade to a previous kernel in Arch Linux (52.8%)
- How to check if my router supports IPv6 (RANDOM - 50%)