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%)
- Analogue of the --force option in pacman (54.8%)
- How to downgrade to a previous kernel in Arch Linux (54.8%)
- bash: finger: command not found in Arch Linux (RESOLVED) (54.8%)
- How to choose the default Java version in Arch Linux (54.8%)
- How to completely uninstall a package along with dependencies on Arch Linux (as well as BlackArch and Manjaro) (RANDOM - 50%)