Why is sudo: bundle command not found?

23,136

Solution 1

Check if the PATH has the same values both with and without sudo. Apparently it cannot find bundle just because it is not listed in PATH

You can compare the outputs of following two lines

$ echo 'echo $PATH' | sh
$ echo 'echo $PATH' | sudo sh

Ideally sudo is supposed to leave PATH untouched. But this might be a side issue of your hosting distribution.

Edit by original poster. Output is:

[root@desktop etc]# echo 'echo $PATH' | sh
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@desktop etc]# echo 'echo $PATH' | sudo sh
/sbin:/bin:/usr/sbin:/usr/bin:/user/local/bin
[root@desktop etc]#

Solution 2

I had this issue I thought that my gitlab installed from source and I got same error. but after try Omnibus method for backup my issue solved with this command:

sudo gitlab-rake gitlab:backup:create

Solution 3

The user was created without a bash login shell. Change this in centos using system-config-users. Then su git into /home/git and move to gitlab directory. Execute the bundle commands without the sudo tag. The next error you will encounter is the missing database.yml in the config dir. fix this with the correct password (i.e. copy the mysql or postgres sample and edit).

Share:
23,136
user1032531
Author by

user1032531

Updated on July 09, 2022

Comments

  • user1032531
    user1032531 almost 2 years

    Why is command "bundle" not found when using sudo:

    [root@desktop gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
    sudo: bundle: command not found
    [root@desktop gitlab]#
    

    but does exist when not using sudo:

    [root@desktop gitlab]# bundle exec rake gitlab:setup RAILS_ENV=production
     Warning
      You are running as user root, we hope you know what you are doing.
      Things may work/fail for the wrong reasons.
      For correct results you should run this as user git.
    
    This will create the necessary database tables and seed the database.
    You will lose any previous data stored in the database.
    Do you want to continue (yes/no)? no
    Quitting...
    [root@desktop gitlab]#
    

    The reason I ask is I am following https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos, and it states to use sudo.

    I've tried adding a -i flag as described by Using $ sudo bundle exec ... raises 'bundle: command not found' error, but get "This account is currently not available.".

  • user1032531
    user1032531 about 10 years
    Please see below: [root@desktop gitlab]# echo 'echo $PATH' | sh /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/‌​bin:/usr/sbin:/usr/b‌​in:/root/bin [root@desktop gitlab]# echo 'echo $PATH' | sudo sh /sbin:/bin:/usr/sbin:/usr/bin:/user/local/bin [root@desktop gitlab]#
  • deimus
    deimus about 10 years
    Try to put following in your .bashrc : alias sudo='sudo env PATH=$PATH'
  • deimus
    deimus about 10 years
    Then rerun all your commands in a new bash sessions, now they should work :) hopefully
  • deimus
    deimus about 10 years
    And let me know if you are still facing problems
  • user1032531
    user1032531 about 10 years
    Thanks deimus. Added that line to the very first line of /etc/bashrc but no change. Tried logging out and back in but still no. Note that /etc/bashrc states "It's NOT a good idea to change this file unless you know what you are doing...". Should I be worried?
  • deimus
    deimus about 10 years
    the .bashrc should never be located under /etc/. Normally its located in home directory /home/<USERNAME>/.bashrc. Please be sure to not affect your other settings
  • user1032531
    user1032531 about 10 years
    To find it, I did find / -name bashrc, and it was in /etc/. Note I am logged in as root user, and I don't have a /root/home/ directory. Sorry for the hard to read outputs of $echo $PATH. I updated your post to show the output.
  • deimus
    deimus about 10 years
    If its not under /home/<USERNAME> just create it and put the line that I've posted.
  • deimus
    deimus about 10 years
    You don't need to touch anything on /root/... just go to your home directory cd ~ then open .bashrc file, note that its a hidden file. Open it add the lines I left in my previous comment and thats it.
  • user1032531
    user1032531 about 10 years
    Did so, and now I get [root@desktop gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production --> env: -u: No such file or directory. Note that before getting your last comment, I put it in /home/get/.bashrc, but then removed it.
  • deimus
    deimus about 10 years
    @user1032531 Please check following documentation about .bashrc . I've to got home now, will message you back a little bit later. tldp.org/LDP/abs/html/sample-bashrc.html
  • user1032531
    user1032531 about 10 years
    Thanks for the help deimus. Turned out I had /user/local/bin in my sudo path, and not /usr/local/bin
  • Jaime Soriano
    Jaime Soriano about 9 years
    In some distributions sudo resets environment variables by default and sets PATH to its secure_path, check your configuration in /etc/sudoers. Take a look to stackoverflow.com/questions/257616/sudo-changes-path-why