Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to run the james smtp server on Lion. When I do this ...

sudo JAVA_HOME=/Library/Java/Home ./james-2.3.2/bin/

... it works fine.

However, I'd like to make JAVA_HOME an environment variable so it is visible to other applications too.

I edited ~/.bash_profile to look like this ...

export JAVA_HOME=/Library/Java/home

... and the variable appears to be visible from the command line like so ...

$ echo $JAVA_HOME

But when I run james again like this, I get a warning about JAVA_HOME ...

$ sudo ./james-2.3.2/bin/
ERROR: JAVA_HOME not found in your environment.

Please, set the JAVA_HOME variable in your environment to match the
location of the Java Virtual Machine you want to use.

Any ideas what I'm doing wrong? Why can't the command to run james see the JAVA_HOME environment variable?

Any info is greatly appreciated, thanks!


share|improve this question
Have a look here: Setting environment variables in OS X – iolsmit Jan 3 '12 at 18:26
up vote 3 down vote accepted

The issue is that you are not running in your environment so any changes to ~/.bash_profile will have no effect on the command. It will be visible to other processes

sudo runs as another user - in this case root as you have not provided a -u username parameter. Thus you need to change the root environment to make JAVA_HOME visible to the command

share|improve this answer
You may also be able to use the -E option to sudo; the man pages say it preserves environment variables, but I have not tested it. – cm2 Dec 29 '11 at 18:07
Thanks -- which file do I edit so the variable is visible to root user? Also, is there a place where I can make the variable visible to the entire system? Thanks! – Robert Hume Dec 29 '11 at 18:07

Your Answer


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.