Configuring Java in Ubuntu

Here is a simple way to configure Java in Ubunu Linux. After following these steps, commands like java and javac will be available in the terminal window.

  • Download the JDK and unpack it somewhere on your system. Let’s use /home/user/bin as an example.
  • Set the file you download to executable. You can do this by right-clicking the file, choose Properties->Permissions.
  • Excecute the file by double-clicking it and choose “Run in terminal” . Say yes a few times and you’re done.

Now you need to make Java available in the path so you can use it from any terminal.

  • Edit the file .bashrc under your home directory and add the following lines

export JAVA_HOME=/home/user/bin/jdk1.5.0_09

export PATH=$JAVA_HOME/bin:$PATH

  • Open a new terminal window and type java -version to make sure you’re running the java version you expected. Type env and verify that PATH variable contains the path to the JDK that you exported before.

14 thoughts on “Configuring Java in Ubuntu

  1. Trying to follow what it says in that page but I cannot even get the java-package:

    anh@anh-laptop:~$ sudo apt-get install fakeroot java-package
    Reading package lists… Done
    Building dependency tree… Done
    E: Couldn’t find package java-package

  2. I think java-package is in the “Universe” repository.
    And don’t forget to execute
    sudo update-alternatives –config java
    sudo update-alternatives –config javac

  3. Ok, I did this and now java -version gives me the correct version. I removed those exports from the .bashrc file but now maven does not find JAVA_HOME. So it is bad to do those exports anyway?

  4. I think the exports must be there. Don’t need to put java in the path though, cause the setup with make-jpkg takes care of that, but still have to have:

    export JAVA_HOME=/usr/lib/j2sdk1.5-sun
    export M2_HOME=/home/anh/bin/maven-2.0.4
    export PATH=$M2_HOME/bin:$PATH

    because maven needs to know where Java is.

  5. A PITA to install java ‘by hand’. Especially when I already installed the 32bit version for web-use, and now want to have 64bit java for azureus. :-/

  6. Thanks yeah!!!! I could install java… I m not a newbie but was still facing lots of problem… and all was resolved following these simple steps religiously….

  7. I have download Java from and installed, however could not get it working as the path was not set.

    Followed your guide by setting the path in the .bashrc, which worked perfectly. Thank you very much!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s