Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

After the upgrade to 10.8.0, whenever I do a sudo, I always get this message:

dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid

I have checked my .bash_profile, .zshrc all I could think of, and I don't see anything related to the DYLD_ environment.

After googling for hours, I tried to put these two lines in my .zshrc:

unset LD_LIBRARY_PATH  
unset DYLD_LIBRARY_PATH

But the annoying message still appears.

I go to a guest account and did a sudo but didnt' get this message. So I guess I have some custom library installed... But I don't know how to debug this.

share|improve this question
add comment

4 Answers

up vote 6 down vote accepted

Do you have any other DYLD_ variables set? Run set with no parameters to see all variables and unset anything that comes up with that prefix.

Note that it looks like this is really just a workaround for a bug, those messages shouldn't be printed unless you have DYLD_PRINT_WARNINGS enabled.

Also, the update to 10.8.1 seems to have patched this annoyance.

share|improve this answer
1  
ML bug, as far as I can tell. Those DYLD_ variables can be important, removing them might break whatever they were set for. –  gabedwrds Jul 30 '12 at 4:24
1  
Well, the bug is that you're not supposed to see those messages unless you set the environment variable DYLD_PRINT_WARNINGS, but for some reason Mountain Lion prints them either way. –  gabedwrds Jul 30 '12 at 4:37
1  
10.8.1 Didn't fix the problem –  Matteo Dec 22 '12 at 14:46
1  
Unsetting all DYLD_ environment variables is not a solution as they are there for a reason. It's a bug and we are stuck with it until Apple fixes it. –  Matteo Dec 22 '12 at 14:47
1  
I have this problem on 10.8.3 –  Alex Szatmary May 1 '13 at 23:33
show 4 more comments

work around found on the apple support forums by yokyoh1987,

https://discussions.apple.com/thread/4143805?start=30&tstart=0

in your .profile/.bashrc/.bash_profile (depends on you terminal setting):

# set DYLD_* for my normal programs
DYLD_LIBRARY_PATH='..'

# set an alternative sudo
thesudo()
{
# back up the DYLD_* variables
local BACK=$DYLD_LIBRARY_PATH

# unset DYLD_*
unset DYLD_LIBRARY_PATH

# calling sudo
/usr/bin/sudo "$@"

# restore DYLD_* after sudo finished
export DYLD_LIBRARY_PATH=$BACK
}

# redirect sudo
alias sudo=thesudo
share|improve this answer
    
That's a clever little piece of env management. –  bmike Dec 28 '12 at 23:17
    
One problem with this solution is that if you interrupt the sudo (e.g., via ctrl-c) your DYLD_LIBRARY_PATH var will silently be left unset in your interactive shell because the restore operation at the end will not have executed. Using a subshell (see my other answer to this question) solves this. –  Pinko Feb 26 '13 at 15:56
add comment

In zsh:

 sudo () { ( unset LD_LIBRARY_PATH DYLD_LIBRARY_PATH; exec command sudo $* ) }

This spawns a sub-shell in which the environment variables that sudo complains about are unset, and then executes sudo.

Advantages over some of the other answers include:

  • Doesn't remove LD_LIBRARY_PATH and DYLD_LIBRARY_PATH from your interactive shell environment (for non-sudo commands that need it).
  • Use of a subshell ensures that if you interrupt the sudo while it's running (e.g., with Ctrl-C), your LD_LIBRARY_PATH and DYLD_LIBRARY_PATH will be unchanged in your master shell (unlike the script in another answer which sets and unsets them in the interactive shell).
  • Use of exec ensures that the otherwise-unnecessary parent shell exits immediately when invoking sudo, so there's no extra processes hanging around while the command runs.

I'll leave it as an exercise to the reader to port to bash, et al.

share|improve this answer
    
"I'll leave it as an exercise to the reader to port to bash, et al." Because most Apple users use ZSH over the preinstalled Bash (sarcasm). –  Jonathan Dumaine Jun 21 '13 at 7:47
add comment

You probably have your LD_LIBRARY_PATH set.

share|improve this answer
1  
As the poster writes, he/she has already unset LD_LIBRARY_PATH, and the problem persists. –  myhd Dec 22 '12 at 13:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.