Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have installed ServiceMix on my machine, and am trying to start it. The startup script is called When I did ./, it gave me a Permission Denied message. So I used sudo ./, which starts the server fine.

However, it seems to be using Java 7, when I would like to use Java 6 (for various reasons). I looked through the script and found that it uses the JAVA_HOME variable. So I set my JAVA_HOME to the JDK 6 directory.

However, ServiceMix still uses Java 7.

A Google search revealed that when a command is run with sudo, sudo removes certain environment variables. So I did sudo -E ./ Again, it used JDK 7.

I opened the and added a line, echo $JAVA_HOME to see whether the variable is set properly or not. The output of echo was an empty line.

I tried modifying the /etc/sudoers file to include Defaults env_keep += "JAVA_HOME". Executing now tells me that my echo statement is again an empty line. ServiceMix still uses JDK 7.

I tried setting JAVA_HOME in /etc/profile. Executing now tells me that my echo statement is again an empty line. Again, ServiceMix uses JDK 7.

What mistake am I doing here?

FWIW, am on Mac OS X 10.8.2. echo $SHELL on my terminal returns /bin/bash. When I use sudo su and fire echo $SHELL, it returns /bin/sh.

share|improve this question
Why not just set JAVA_HOME explicitly in – Tim B Mar 10 '13 at 15:31
Why not sudo chmod the file so that the program can run at user-level privileges – Clayton Stanley Mar 12 '13 at 6:14

2 Answers 2

I would suggest you to try out the following steps:

  1. Inside /etc/profile.d directory, create a file named file containing the line

    export JAVA_HOME=<_complete_path_to_java6_directory_>

  2. Run bash command once to make the above change to load. And run the script.


If the /etc/profile.d directory doesn't exist, create a directory names same (permission: 0755 & owner and group as root) and inside your /etc/profile file, add the following code:

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
  unset i
share|improve this answer
I don't seem to have a /etc/profile.d directory. Should I create it? – Shivasubramanian A Mar 10 '13 at 6:48
@ShivasubramanianA: I have updated the answer. – pradeepchhetri Mar 10 '13 at 6:59

To preserve your environment variables as sudoer add Defaults env_keep += PATH to your sudoer file (sudo visudo).

share|improve this answer
i upvoted for the intent of the answer, and because I learned something new. note that OP is asking about JAVA_HOME, not PATH, though that's trivial and the answer would be the same. – Tim Kennedy May 14 '13 at 16:58

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.