Posted by & filed under Java, Linux, Software.

Here is just an example of how to install java 7 on your linux.
I use current Debian and oracle (former sun) java 7.

First i had to download the latest java from oracle site and then extract it. I have to do it because at the moment the is no official debian package for java 7.
So we are not able to do it with apt-get as we can it for java 6.

tar zxvf jdk-7-linux-x64.tar.gz -C /usr/lib64/jvm/

Then we have to do some configuration.
Debian Linux has useful script to maintain different version of one programs like java called update-altenatives. So i simply use this.

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/bin/java 1065
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0/bin/javac 1065

Where 1065 is a given priority.

To check my installation i use –config paramter

update-alternatives --config java
#this prints:
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                      Priority   Status
* 0            /usr/lib/jvm/jdk1.7.0/bin/java             1065      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/jdk1.7.0/bin/java             1065      manual mode</pre>

And because 1065 is higher than 1061, the fresh installed java 7 will be used by default on my machine

java -version
java version "1.7.0"
 Java(TM) SE Runtime Environment (build 1.7.0-b147)
 Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

Hope this save somebody some setup time.

Share if you likeTweet about this on TwitterShare on FacebookShare on Google+Share on RedditShare on LinkedInBuffer this pageEmail this to someone
  • Gonçalo Sousa

    Hi, great post, it really helps
    It only has a small “bug” in there, that i took about 30 mints to find. In the second line of the “update-alternatives” you have java when it should be javac. Like this:
    update-alternatives –install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0/bin/javac 1065

  • shuron

    Thank you Gonçalo Sousa.
    It’s fixed now 😉

  • Mateusz@Raporty Allegro

    Thank You very much. I installed JDK 7 and it works good. But I’m a little bit disappointed. My primary goal in installing 7 was to increase performance (I’ve read that it is much faster than JDK 6). But after installation I run a small benchmark (mainly memory operations: allocation, array copy and GC). I was disenchanted. JDK 7 is not faster than 6, but it appears a little bit slower :(

    Average from 10 runs:
    JDK 6: 704 [ms]
    JDK 7: 715 [ms]

    Maybe the next updates will be faster (now I use JDK 7u1).

  • shuron

    Halle Mateusz,
    creation of good benchmark is not so simple as it may appear. There are things like HotSpot Dynamic Compilation, garbage collection and other performance and resource management of vm that shold be considered, but can’t be measured 100%.
    I any case you have to skip the warm up Phase in your benchmark and please dont’ expect to much by such benchmarks (Rule 0).

    You are invited to post your benchmark code here and we can try it on our self or maybe improve it.

    P.S. difference in 11ms is still Ok due typical System.currentTimeMillis() accuracy which is typical +- 15 ms on most OS + JVM combinations :)

  • Jorge

    Thanks a lot!!

    I was trying to find a way how to install Java in Debian testing. Finally i could make it, all thanks to your explanation.

    It works perfect for dummies like me. Thanks!

  • shuron

    You welcome Jorge!
    P.S. You can’t be a dummy as long you are interested in java technology 😉

  • Mikal

    Saved me some time!
    Thanks a lot!

  • Anas Bouhtouch

    Thanks man, this really helped me. 😉

  • shuron


  • BlessSonic


    Worked like a charm!

  • shuron
  • Stefan


    thx for this great tutorial.

    I just made a little adjustment:
    I used /usr/local/lib/… as this is the folder for users. /usr/lib/ is for the system (aptitude).
    And you should differ between lib and lib64


  • shuron

    Agree with you about /usr/local/lib/
    I wrote about 64-bit java it’s true. So in a stadard conform way we to create in /usr/local/lib64/ (soft) links to /usr/local/lib/.
    Please correct me if i’m wrong.

    Src: Linux Filesystem Hierarchy.

  • Lucius

    Thank you, I was in trouble with configurtion of java 7. It worked like a charm in Debian 6 Squeeze.

  • John Comeau

    update-alternatives didn’t actually change the symlinks in /etc/alternatives for me, even though update-alternatives –config java shows the new (1.7) being automatic. I can change them by hand, but any idea why it didn’t work? I got no error message once I ran the commands using sudo.

  • shuron

    Strange. Which debian version we are talking about?
    I didn’t have such problems with debian lenny or squeeze.
    Check carefully path again, wrong path maybe is not reportet by update-alternatives command.

  • John Comeau

    wheezy/sid. path had to be correct because I used Bash autocomplete as I was typing it in. anyway it was easy to fix the links manually with ln -sf /new/path/to/javac /etc/alternatives/javac

  • mlebel

    God, this has saved me alot of grief.
    Thank you so much!

    I used to have a how-to like this for debian etch, and I seem to have lost it.. your site is a saver!

  • Koss

    good link fo install jdk7

  • shuron

    Thank you. It’s usefull. But does to much for my case (X11 free server)

  • mike kim
  • Tomek

    Thanks, it works perfect!

  • heerdyes

    thanks a lot. was a great help.
    wget couldn’t get the jdk tar.gz file though.
    “DownThemAll”ed it.
    would that be due to the “accept license agreement” part?

  • shuron

    Maybe something has changed on the oracle site. “accept license agreement” was not a problem earlier.

  • kamyk

    “accept license agreement” & “registered users only” can download packages

  • Gonçalo
  • kujirasan


    I am trying to install those two above! I have managed to extract them into lib64/jvm folder, the linking fails, the method you have outlined in linking is to the lib folder :
    /usr/lib/jvm/ while the extraction is directed to lib64/jvm,
    is that a problem, as how would you modify the script for the
    jdk-7u4, in the usr/lib/jvm/jdk1.7.0

    This the error I get
    alternative path /usr/lib/jvm/jdk1.7.0_4/bin/java doesn’t exist

  • aw


    Took me all day to get sun-java into debion wheezy.
    Your post made it work.

    Question though: doesn’t java 7 interfere with openjdk?
    How to remove openjdk the best way?

    cheers and thanks!

  • shuron

    Hi, nice to here this helps someone.
    To you question:
    No, it should not interfer. just use one or another, if installed correct no iterference problems should appear.

    And you can remove openjdk with your packet manager if you installed it that way. E.g:

    apt-get purge openjdk-\*

  • aw

    Quick response, thank you!

    In addition to your update-alternative lines (java, javac), I found an other one on an other website…Javaw..? Important?

    I am not out of the woods yet. Although Java seems to be installed, I can not find a way to activate it for Google chrome. Any suggestions?


  • shuron

    Hi, you usually will not need Javaw (Java Viewer) if you don’t know what it is.

    This will help you with enabling java-plugin in chrome on linux.
    But i didn’t tried.

  • AW


    Appreciate the way your explanation.

    I may have two other subjects for your blog.

    First of all, I am a newbie getting lost pretty fast in the technical explanations. So sollutions which I can understand are difficult to find.

    Suggestions for a blog:

    – How to optimise performance of java?
    (response, latency, etc.)

    – The second one is actually more of a question. I have to log in via the internet (and thus a browser) to an other computer. This computer has a java interface and java screen. Would “a more” direct link (avoiding the browser) improve performance of java?

    It does not fit this blog, so take it out if you please.

    Would appreciate your thoughts though.


  • shuron

    Hallo AW.
    Your qustion is fussy.
    -Some system
    -Something with java.
    I can’t answer it properly. Please more details! 😉

  • aw

    my questions:

    (it doesn’t have to do anything with this blog btw)

    1) I have to log in on an internet site for work.
    This site java. I contact the site through a browser.

    Would speed be better if I could avoid the use of the browser, and contact the site directly. If yes, could you point out a direction of a (Java)solution.

    2) Are there particular settings to improve performance of java jre?

  • Juan

    Thank you. I didn’t know that update-alternative tool this will help me in the future.

  • neph04

    Thank you!

  • Jay

    Thank you.
    After a full day of trying install different Javas
    ( and making quite a mess), I found your post.
    I’m trying jre1.7.0_05.
    Fingers crossed…

    Thanks again,

  • Sebastian

    You can also do it an even more debian way with java-package:
    ….but only fro debian wheezy onwards I should add.

  • shuron

    Yes, of course.
    But it’s different branch: openjdk 😉

  • _jpgo

    Gracias, excelente!!!

    Saludos from Santiago de Chile

  • adacenter07

    How do I tell APT that java is installed? I want to install a package that requires java and now it always wants to download openjdk-6-jre and shit.

  • shuron

    Meanwhile there are several packagess availabel that you can install with apt. Look here: if there is a package with a dependency to openjdk-6-jre you can isntall it with:
    $apt-get install openjdk-6-jreAnd I do not think that there is another way  to say apt “installed” than to perform the installation of desired package.

  • kostasx

    Really helpful. Thanks…

  • DebianDummy

    “… download the latest java from oracle site and then extrat it. ”
    Should that be “extract it”?

  • shuron

    @DebianDummy  Thank you. Fixed now.

  • Herman Leao

    Thanks man. You’re cleared my head a lot. Yep. Good Christmas for u and all family.

  • will

    Thank you so much – I spent hours trying to figure this out, and I was completely lost before you helped!

  • souzace


  • Dude

    To automate the download using WGET, use:wget –no-cookies –header “Cookie:” -O jdk-7-linux-x64.tar.gz “”

  • shuron

    Works Perfect!
    Thank you Dude!  ;))