I have Java 1.6 installed on my Linux box and all users and programs used it. Now, I need to install a program which uses version 1.7. I want to install this version such that everyone else continues to use 1.6, except that new program. What I am thinking is to install new Java and to keep $JAVA_HOME to point to the old Java 1.6. For that particular process, executed by a separate user, I want to set $JAVA_HOME to point to java 1.7

Is this going to work? It will not overwrite the original $JAVA_HOME? Is it sufficient $JAVA_HOME to point to new java for everything to work?

Note: I don't want that the program to be executed under Java 1.7, the program calls a scripts which must run under 1.7. I don't have permissions neither to modify the program, nor those scripts.


1 Answer 1


You have to worry about more than just $JAVA_HOME; you also need to set $PATH if you are going to call the commands without an absolute path. ie java and not /opt/java/1.7/bin/java.

Now depending on how your script works or how you call java, you have a few options.

Bash Script

Doing it this way means you do not need to add an extra user




If you want to use another user putting this in your .bashrc is an option. export is used so that $JAVA_HOME and $PATH are made into environment variables.

export JAVA_HOME=/opt/java/1.7
export PATH=/opt/java/1.7/bin:$PATH


You can also set these environment variables on the fly for a single command and its sub commands

eval JAVA_HOME=/opt/java/1.7 PATH=/opt/java/1.7/bin:$PATH java ${ARGS}

You must log in to answer this question.

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