Take the 2-minute tour ×
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 start.sh. When I did ./start.sh, it gave me a Permission Denied message. So I used sudo ./start.sh, 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 start.sh 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 ./start.sh. Again, it used JDK 7.

I opened the start.sh 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 start.sh 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 start.sh 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
1  
Why not just set JAVA_HOME explicitly in start.sh? –  Tim B Mar 10 '13 at 15:31
    
Why not sudo chmod the start.sh file so that the program can run at user-level privileges –  Clayton Stanley Mar 12 '13 at 6:14

2 Answers 2

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

I would suggest you to try out the following steps:

  1. Inside /etc/profile.d directory, create a file named set_java_path.sh 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 start.sh script.

Edit:

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
    fi
  done
  unset i
fi
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

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.