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.
About these ads

15 Responses to “Configuring Java in Ubuntu”

  1. Stephan Michels Says:

    Gosh! Didn’t you ever heard from java-package and make-jpkg?

  2. Ana Says:

    Not untill you posted that comment. Did you read the title of my blog? Thanks for the tip anyway, I found this website http://www.debian-administration.org/articles/142 and I am reading about it. Cheers!

  3. Ana Says:

    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
    Password:
    Reading package lists… Done
    Building dependency tree… Done
    E: Couldn’t find package java-package

  4. Stephan Michels Says:

    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

  5. Ana Says:

    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?

  6. The good way to configure Java in Ubunto « Jump Start Says:

    [...] Jump Start confessions of a newbie « Configuring Java in Ubuntu [...]

  7. Ana Says:

    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.

  8. Ana Says:

    This post has been deprecated :P Please read the next one.

  9. Ubuntuuser Says:

    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. :-/

  10. pall Says:

    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….

  11. pall Says:

    sorry tht was posted by mistake its meant for another site

  12. wasim Says:

    thanks very benificial thread for beginners

  13. Esen Says:

    I have download Java from java.com 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!

  14. suchandra Says:

    Thanks .. this works.
    The .bashrc is hidden file. So in “view” select “Show hidden files”

  15. rajeesh r Says:

    How can i run the executable jar file on ubuntu startup.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: