Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have installed both OpenJDK 6 and 7. When I run "java somefile" from the command line, OpenJDK 6 is invoked. I do not want to change this default behavior. What command can I use to run my non-default OpenJDK 7 installation instead?

(I am used to running "python somefile" to invoke the default Python, "python2.7 somefile" to use Python 2.7 specifically and "python3 somefile" to use Python 3 specifically.)

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You could bind an alias to the specific java versions. Just add the following lines to your $HOME/.bashrc:

alias java6='/path/to/java6/bin/java'
alias java7='/path/to/java7/bin/java'

Same for javac and you should be fine ;-)

share|improve this answer
1  
the paths to the different java executables look like: /usr/lib/jvm/java-7-openjdk-amd64/bin/java –  ImaginaryRobots Sep 5 '12 at 15:25

You can select java version using update-alternatives command.

Run below command in terminal.

sudo update-alternatives --config java

And type selection number that you want to use.

Like this:

selecting java version

Caution: The above description is the procedures for changing a default version. It is not an answer of this question, but it leaves for reference.

share|improve this answer

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.