14

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

Community
  • 1
  • 1
user1032531
  • 24,767
  • 68
  • 217
  • 387
  • I've installed Gitlab on a Gentoo box recently and found that the git user needed a valid shell and home directory for the installation to succeed. Apparently, there's a commit on the Gitlab source which obsoletes this, but it's not yet part of the released Gitlab version. – svoop Mar 17 '14 at 15:08
  • I have the exact same issue except I'm running into the error on this command to install the gem: 'sudo -u git -H bundle install --deployment --without development test mysql aws'. I'm running Ubuntu 12.04 server. – ericso Jun 10 '14 at 16:37
  • Possible duplicate of [Command not found when using sudo](https://stackoverflow.com/questions/12996397/command-not-found-when-using-sudo) – Raedwald Dec 05 '18 at 12:20

4 Answers4

20

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]#
deimus
  • 9,565
  • 12
  • 63
  • 107
  • 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/bin:/root/bin [root@desktop gitlab]# echo 'echo $PATH' | sudo sh /sbin:/bin:/usr/sbin:/usr/bin:/user/local/bin [root@desktop gitlab]#` – user1032531 Mar 17 '14 at 15:12
  • 2
    Try to put following in your `.bashrc` : `alias sudo='sudo env PATH=$PATH'` – deimus Mar 17 '14 at 15:15
  • Then rerun all your commands in a new bash sessions, now they should work :) hopefully – deimus Mar 17 '14 at 15:16
  • And let me know if you are still facing problems – deimus Mar 17 '14 at 15:23
  • 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? – user1032531 Mar 17 '14 at 15:33
  • the `.bashrc` should never be located under `/etc/`. Normally its located in home directory `/home//.bashrc`. Please be sure to not affect your other settings – deimus Mar 17 '14 at 15:34
  • 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. – user1032531 Mar 17 '14 at 15:37
  • If its not under `/home/` just create it and put the line that I've posted. – deimus Mar 17 '14 at 15:37
  • 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. – deimus Mar 17 '14 at 15:39
  • 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. – user1032531 Mar 17 '14 at 15:43
  • @user1032531 Please check following documentation about .bashrc . I've to got home now, will message you back a little bit later. http://www.tldp.org/LDP/abs/html/sample-bashrc.html – deimus Mar 17 '14 at 15:44
  • Thanks for the help deimus. Turned out I had `/user/local/bin` in my sudo path, and not `/usr/local/bin` – user1032531 Mar 17 '14 at 17:01
  • 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 http://stackoverflow.com/questions/257616/sudo-changes-path-why – Jaime Soriano Apr 01 '15 at 19:37
1

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

1

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

Mohammad Ravanbakhsh
  • 2,244
  • 1
  • 15
  • 26
0

Try :

sudo -u git -H env PATH=$PATH && bundle exec rake gitlab:check RAILS_ENV=production

to use the same PATH than current user.

Simon Oualid
  • 365
  • 2
  • 9