dpkg: warning: 'ldconfig' not found in PATH or not executable - Ubuntu 12 - Vagrant
Because you are piping your wget to a new shell, the environment is not preserved.
To prove this, try the following from inside your vagrant box
root@lucid32:~# export PATH=$PATH:/foo
root@lucid32:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/vagrant_ruby/bin:/foo
Now run the same command as a different user
root@lucid32:~# su -l vagrant -c 'echo $PATH'
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/vagrant_ruby/bin
Compare the output of both commands and you will see that the environment is not preserved on the child shell. (/foo disappeared)
To make the environment persistent, use --preserve-environment
or -p
or -m
. All 3 are equivalent.
root@lucid32:~# export PATH=$PATH:/foo
root@lucid32:~# su --preserve-environment -l vagrant -c 'echo $PATH'
-su: /root/.bash_profile: Permission denied
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/vagrant_ruby/bin:/foo:/opt/vagrant_ruby/bin
Don't worry about the permission denied error, that is expected
Solutions
Solution 1.
Use -p
, -m
or --preserve-environment
su --preserve-environment -l vagrant -c 'wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh'
Tested on lucid32 vagrant box (10.04)
Solution 2.
If your puppet manifest runs before your heroku script, simply add /sbin to the vagrant user's path through puppet
Tested lucid32 with the following commands
root@lucid32:~# su --preserve-environment -l vagrant -c 'wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh'
-su: /root/.bash_profile: Permission denied
This script requires superuser access to install apt packages.
You will be prompted for your password by sudo.
--2013-08-20 07:40:13-- https://toolbelt.heroku.com/apt/release.key
....
root@lucid32:~# su vagrant -
vagrant@lucid32:/root$ heroku login
Enter your Heroku credentials.
Email:
Related videos on Youtube
Dave Collins
Updated on September 18, 2022Comments
-
Dave Collins over 1 year
I am working on setting up a Vagrant / Puppet install so that new developers can have a clean development environment for our Rails project.
The basic Vagrant configure commands are:
config.vm.box = 'precise32' config.vm.box_url = 'http://files.vagrantup.com/precise32.box'
Overall, the install seems to be going well. I've got RVM, Postgres, and Ruby installed and running.
However, whenever I try to install the "Heroku Toolbelt" using this command:
su -l vagrant -c 'wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh'
I run into this problem:
... Lots of Hits and downloads... The following extra packages will be installed: foreman heroku libruby1.9.1 ruby1.9.1 Suggested packages: ruby1.9.1-examples ri1.9.1 graphviz ruby1.9.1-dev The following NEW packages will be installed: foreman heroku heroku-toolbelt libruby1.9.1 ruby1.9.1 0 upgraded, 5 newly installed, 0 to remove and 132 not upgraded. Need to get 0 B/4,997 kB of archives. After this operation, 13.1 MB of additional disk space will be used. dpkg: warning: 'ldconfig' not found in PATH or not executable. dpkg: warning: 'start-stop-daemon' not found in PATH or not executable. dpkg: error: 2 expected programs not found in PATH or not executable. Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin. E: Sub-process /usr/bin/dpkg returned an error code (2)
(Note) This happens if I run the command manually after vagrant ssh. Also, the actual shell configuration gets the error when it initially runs.
Since this is a vagrant box, it is easy to 'vagrant destroy' and then try again but I get the same issue consistently.
The strange thing is, my PATH does definitely include those folders:
echo $PATH /home/vagrant/.rvm/gems/ruby-1.9.3-p194/bin:/home/vagrant/.rvm/gems/ruby-1.9.3-p194@global/bin:/home/vagrant/.rvm/rubies/ruby-1.9.3-p194/bin:/home/vagrant/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant_ruby/bin
the file 'ldconfig' is in /sbin and is an executable:
cd /sbin ls -l l* -rwxr-xr-x 1 root root 465 Apr 20 2012 ldconfig
Same with start-stop-daemon:
-rwxr-xr-x 1 root root 26752 Apr 12 2012 start-stop-daemon
So, not sure what it is really complaining about... Any suggestions? Some permissions issue with Vagrant?
-
Dave Collins over 10 yearsThanks @spuder for your well-clarified answer! I'm having some trouble though. When I try your example of su --preserve-environment -l vagrant -c 'echo $PATH' the /foo still doesn't show (just as it doesn't in your first example) I destroyed and recreated the box and same thing. I'll keep playing around... Your comments have at least given me some leads!
-
Tony Anderson over 10 years@DaveCollins I just double checked my steps, and it works for me. /foo will only exist on the shell until it is closed. make sure you don't logout, or reboot the machine in the middle of the test.
-
Dave Collins over 10 yearsWell, for whatever reason the --preserve-environment just does not work on my vagrant box. However, I just tried the internal command without sudo and it ran just fine! Very odd. Your answer gave me much insight as to what was going wrong, though!