Setting up Ubuntu 12.04 for Java development

15:21 , , , 46 Comments

In this post I will describe steps I have followed after fresh install of new Ubuntu 12.04 LTS. Linux is great environment for Java development and I am using for several years now. In my last work I had to maintain projects running on different versions of Java. This instruction gives some hints how you can deal with this situation effectively. Moreover I describe how to change GUI outline in Eclipse to be more compact using GTK configuration files.


I prefer installing Java manually. As I mentioned before I need to have several versions of Java including 1.5, 1.6 and 1.7. First step is to download required files from oracle site:

Choose Linux files for your OS architecture (i586 for 32-bit version of Ubuntu and x64 for 64-bit version). You should download files with .bin extension (for 1.5 and 1.6 JDK versions) or .tar.gz (1.7 JDK). After downloading, you should have following files in Downloads directory:
stanislaw@latitude:~/Downloads$ ls -l
total 212888
-rw-rw-r-- 1 stanislaw stanislaw 49760685 Jun  8 14:42 jdk-1_5_0_22-linux-i586.bin
-rw-rw-r-- 1 stanislaw stanislaw 85292206 Jun  8 14:43 jdk-6u31-linux-i586.bin
-rw-rw-r-- 1 stanislaw stanislaw 82927766 Jun  8 14:37 jdk-7u4-linux-i586.tar.gz
We will install all jdk's in /opt/java directory. First create directory:
sudo mkdir /opt/java
Now extract jdk-7 file and simply move it do /opt/java directory:
stanislaw@latitude:~/Downloads$ tar zxvf jdk-7u4-linux-i586.tar.gz
stanislaw@latitude:~/Downloads$ sudo mv jdk1.7.0_04/ /opt/java
To install jdk 1.5 and 1.6 first make bin files executable with chmod command:
stanislaw@latitude:~/Downloads$ chmod +x jdk-1_5_0_22-linux-i586.bin jdk-6u31-linux-i586.bin
Now run this executables (you will be shown license agreement; press q and confirm it by typing yes):
stanislaw@latitude:~/Downloads$ ./jdk-1_5_0_22-linux-i586.bin
stanislaw@latitude:~/Downloads$ ./jdk-6u31-linux-i586.bin
Right now 1.5 and 1.6 JDK are in Downloads directory. Move them to /opt/java:
stanislaw@latitude:~/Downloads$ sudo mv jdk1.5.0_22/ /opt/java/
stanislaw@latitude:~/Downloads$ sudo mv jdk1.6.0_31/ /opt/java/
Create symbolic links in /opt/java directory. This will simplify updating process to changing particular symbolic link.
stanislaw@latitude:~/Downloads$ cd /opt/java/
stanislaw@latitude:/opt/java$ sudo ln -s jdk1.5.0_22 jdk-1.5
stanislaw@latitude:/opt/java$ sudo ln -s jdk1.6.0_31/ jdk-1.6
stanislaw@latitude:/opt/java$ sudo ln -s jdk1.7.0_04/ jdk-1.7
Now it is time to set up java, javac and java plugin. It is best done with update-alternatives utility program. More information about this setup can be found Please note usage of paths to symbolic links created in previous step.
stanislaw@latitude:/opt/java$ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk-1.5/bin/java" 2
stanislaw@latitude:/opt/java$ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk-1.6/bin/java" 1
stanislaw@latitude:/opt/java$ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk-1.7/bin/java" 3

stanislaw@latitude:/opt/java$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/java/jdk-1.7/bin/javac" 3
update-alternatives: using /opt/java/jdk-1.7/bin/javac to provide /usr/bin/javac (javac) in auto mode.
stanislaw@latitude:/opt/java$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/java/jdk-1.6/bin/javac" 2
stanislaw@latitude:/opt/java$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/java/jdk-1.5/bin/javac" 1

sudo update-alternatives --install "/usr/lib/mozilla/plugins/" "" "/opt/java/jdk-1.6/jre/lib//i386/" 1
Last step is setting JAVA_HOME environment variable in .bashrc. Simply add this line at the end of file, to keep java 1.6 as default. Please note that we do not need to set PATH variable, because we used update-alternatives utility to setup /usr/bin/java symbolic link. When I need to work with different version of Java, I simply override default JAVA_HOME value for specific application, i.e. JBoss AS.
export JAVA_HOME=/opt/java/jdk-1.6


Download Linux version, extract it, and move to /opt directory:
stanislaw@latitude:~/Downloads$ tar zxvf eclipse-jee-indigo-SR2-linux-gtk.tar.gz
stanislaw@latitude:~/Downloads$ sudo mv eclipse /opt/eclipse
Application should be ready to run with default executable /opt/eclipse/eclipse. In gtk environment spacing between GUI components seam to be to big. This can be hopefully fixed by customized gtk configuration based on this blog post. One thing I have added, is tool tip background and foreground configuration, to make it visible (see bug report).
stanislaw@latitude:/opt/eclipse$ cat eclipse-gtkrc
style "gtkcompact" {
font_name="Sans 9"
class "GtkWidget" style "gtkcompact"

style "gtkcompactextra" {
class "GtkButton" style "gtkcompactextra"
class "GtkToolbar" style "gtkcompactextra"
class "GtkPaned" style "gtkcompactextra"

style "tooltip" { bg[NORMAL] = "#FFFFFF" fg[NORMAL] = "#000000" }
widget "gtk-tooltips" style "tooltip"
In order to override gtk configuration for eclipse only, it is most convenient to prepare additional script with GTK2_RC_FILES environment variable set.

export GTK2_RC_FILES=/opt/eclipse/eclipse-gtkrc

Last step is to add launch icon. This can be done in several ways described here. I prefer method with manual creation of .desktop file. It can be easily used to add launch icon for any other application installed this way.
stanislaw@latitude:~$ cat /usr/share/applications/eclipse.desktop 
[Desktop Entry]


Installing other java development software like maven, ant is simply done by extracting downloaded zip archives (I personally always use /opt directory) and setting specific environment variables like PATH and ANT_HOME. During my fresh install I installed additionally following packages:
# package libsvn-java is required by subclipse plugin
sudo apt-get install libsvn-java
# version control
apt-get install git svn
# my favorite terminal editor
sudo apt-get install vim
# MS fonts
sudo apt-get install ttf-mscorefonts-installer
# testing frontend configuration for production environment with apache
apt-get install apache2
# ... and many more


Software engineer specializing in delivering highly interactive web applications and complex enterprise systems.


  1. I had a look at some Java examples at that were worth noticing, and they helped learning fundamentals of Java programming practically.

  2. I learned installing Java successfully and created my first mobile app a few days ago, and it was truly a fun experience. I did it under the guidance of Java experts.

  3. I’m really impressed with your blog article, such great & useful knowledge you mentioned here..Get more Java Training in Marathahalli
    Python Training in Marathahalli

  4. And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had

    Java Training in Bangalore|

  5. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.

    Besant Technologies

  6. • I and my friends were going through the nice, helpful tips from the blog then the sudden came up with an awful suspicion I never expressed respect to the website owner for those secrets. AWS Training in Bangalore

  7. I wish to show thanks to you just for bailing me out of this particular
    trouble.As a result of checking through the net and meeting
    techniques that were not productive, I thought my life was done.

    Selenium Training in Bangalore

  8. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.

    Java Training in Bangalore

  9. Much obliged for one superb posting! I appreciated understanding it; you are an extraordinary creator. I will make a point to bookmark your blog and may return sometime in the not so distant future. I need to energize that you proceed with your extraordinary posts, have a pleasant end of the week!... Java Training in Chennai
    Unix Training in Chennai

  10. Informative blog and it was up to the point describing the information very effectively. Thanks to blog author for wonderful and informative post...
    Java training in Chennai || J2ee training in Chennai

  11. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating.
    oracle training in chennai|| hadoop training in chennai

  12. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    hadoop training in chennai || selenium training in chennai

  13. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating. Java training in Chennai

  14. You have provided a nice article, Thank you very much for this one. And I hope this will be useful for many people. And I am waiting for your next post keep on updating these kinds of knowledgeable things
    Java Training in Chennai
    Java Training in Coimbatore
    Java Training in Bangalore

  15. Excellent blog thanks for sharing Run your salon business successfully by tying up with the best beauty shop in Chennai - The Pixies Beauty Shop. With tons of prestigious brands to choose from, and amazing offers we’ll have you amazed.

  16. Awesome blog thankks for sharing 100% virgin Remy Hair Extension in USA, importing from India. Premium and original human hair without joints and bondings. Available in Wigs, Frontal, Wavy, Closure, Bundle, Curly, straight and customized color hairstyles Extensions.

  17. Very useful blog thanks for sharing IndPac India the German technology Packaging and sealing machines in India is the leading manufacturer and exporter of Packing Machines in India.

  18. I really appreciate your method to explaining, I hope to see more posts from your blog. thank you!
    Digital Marketing Course In Kolkata
    Web Design Course In Kolkata
    SEO Course In Kolkata

  19. Nice blog, it’s so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job. Thank you for this wonderful sharing with us good job
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

  20. This article content is really unique and amazing. This article really helpful and explained very well's i am really thankful to you for sharing keep it up..

    Digital Marketing Service in Kanpur

  21. This blog is really helpful to deliver updated affairs over internet which is really appraisable. Sophos Partner Brisbane