Phill Pafford
Phill Pafford

Reputation: 85318

How to use a different version of Java on the command line

OK I have 2 different version of Java install on my machine (CentOS 5), the system defaults to 1.5.0_14 but I need to run a command on the command line with the newer version of Java. How can I pass the newer version in the command line?

Sorry this is such a n00b question but I googled and didn't find anything, thanks.

Upvotes: 3

Views: 11170

Answers (3)

foobarfuzzbizz
foobarfuzzbizz

Reputation: 58637

You could make a link to the file:

ln myJava1 <java version you want>
ln myJava2 <java version you want>

and then when you want one or the other, type the appropriate link.

Or if you want a standard java and just have the other for one offs, you could do:

ln theJava <myJava1 or myJava2>

and then just use theJava (or whatever you want to call it

Upvotes: 1

Robert Munteanu
Robert Munteanu

Reputation: 68268

Use the absolute path to the java executable:

/opt/java-1.4/bin/java

Upvotes: 3

pauljwilliams
pauljwilliams

Reputation: 19225

Just use the full pathname for your java executable, rather than allowing the OS to pick one based on your PATH.

Upvotes: 6

Related Questions