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/run.sh

... 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/run.sh
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!



1 Answer 1


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 run.sh command

  • 1
    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
    Commented Dec 29, 2011 at 18:07
  • 1
    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! Commented Dec 29, 2011 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .