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.

By default my ubuntu system is installed with the following java version:

java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

If I type which java it tells me /usr/bin/java.

Now, I have just installed Oracle's Java from their website and have unpacked it inside the directory: opt/local

How do I make the default Java start from opt/local so that I am using Oracle Java instead of OpenJDK? Is this something I need to auto-configure inside my bashrc? ` Thanks, and if you need more information let me know!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Ubuntu's alternative command management will be helpful here I think.

It's basically organized this way

generic link(e.g. /usr/bin/java) -> buffer link(e.g. /etc/alternatives/java) -> actual command or executable (e.g. /opt/jdk/java)

So you can update the buffer link so that it points to your choice of actual command/executable and still use the generic link to get the job done everywhere as before (of course assuming both commands provides proper functionality ;).

Here is a nice guide to update JVM of your choice through update-alternatives command. So do the following

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/local/jdk-xx.xx/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/local/jdk-xx.xx/bin/javac" 1

You can go on and update the java browser plugin and web-start plugin too as mentioned in the guide. Then choose the java of your choice by

sudo update-alternatives --config java
sudo update-alternatives --config javac
share|improve this answer
    
This will work if you did the manual installation from their site. Honestly, though, I would have used the webupd8team's Java PPA which would have automatically updated java alternatives. –  Thomas W. Jul 20 '13 at 19:17
1  
OP says he unpacked it in /opt/local, so most probably he downloaded the tar.gz package I guess. –  Samik Jul 20 '13 at 19:18
    
I put that comment there so that next time people won't have to deal with this. Besides, Oracle has already said OpenJDK is a suitable equivalent in Linux for their Java, and therefore they aren't going to be updating Java for Linux very much. –  Thomas W. Jul 20 '13 at 19:21
    
@ThomasW. no problem, it was an useful addition. –  Samik Jul 20 '13 at 19:25
    
How will I know which java version is being used now? If I use the which command it still tells me /usr/bin/java –  CodeKingPlusPlus Jul 20 '13 at 19:53
show 1 more comment

Try doing update-alternatives --config java and then follow the prompts to change the default Java environment.

share|improve this answer
    
it does not see the java that I installed in /opt/local –  CodeKingPlusPlus Jul 20 '13 at 19:09
    
@CodeKingPlusPlus How did you install Java? With their autoextracting .run file? –  Thomas W. Jul 20 '13 at 19:09
    
I unpacked a tar file into /opt/local –  CodeKingPlusPlus Jul 20 '13 at 19:44
    
@CodeKingPlusPlus yeah that explains the situation, their tarball does not automatically configure the system. –  Thomas W. Jul 20 '13 at 23:20
add comment

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.