7

I'm using Ubuntu 10.10 and downloaded jdk7 from java.sun.com. That jdk is a compressed file and on extraction there I got all the files and folders of jdk1.7.0.

But now if I tries to compile a java program than there is an error that javac not found.
How could I set PATH of jdk1.7.0\bin to use javac everywhere?

  • 1
    Can't you find your answer here ? http://askubuntu.com/questions/3744/how-do-i-modify-my-path-so-that-the-changes-are-available-in-every-terminal-sessi – danjjl Sep 27 '11 at 12:59

4 Answers4

11

A better way to install the Sun JDK is like so:

Use update-alternatives to do all the heavy lifting for you.

In any case, updating the PATH is a very basic command.

  • In the default bash shell:

    export PATH=$PATH:/your/path

  • For csh use:

    setenv PATH $PATH:/your/path

Edit: Note that this is indeed the instructions for installing Java 6 and not Java 7, which is still - as of now - not available in any official repository or ppa.

Yuval A
  • 307
  • 1
    export PATH=$PATH:/your/path would be if he is using bash. For csh use setenv PATH $PATH:/your/path – Dan Sep 27 '11 at 13:17
  • True. I added a clarification. – Yuval A Sep 27 '11 at 13:42
  • Is there really a sun-java7-jdk in that repository? I can't find it - maybe because I'm using x64? – elmicha Sep 27 '11 at 22:37
  • @YuvalA: the export PATH=$PATH:/your/path is only working where I'd installed the jdk1.7.0/bin but if I place the java program elsewhere then how would I be able to compile the program? – Mohammad Faisal Sep 28 '11 at 04:34
  • @Dan: setenv PATH $PATH:/your/path also not working. – Mohammad Faisal Sep 28 '11 at 04:38
  • Hmm, turns out Oracle Java 7 isn't going to be available in any Ubuntu repository due to licensing issues. What you have up there is basically how you would install Sun Java 6. However my answer does describe the proper way to install redundant packages and how to use update-alternatives to manage symlinks to various versions. In any case, for Java 7 see http://www.webupd8.org/2011/09/how-to-install-oracle-java-7-jdk-in.html – Yuval A Sep 28 '11 at 09:06
  • Thanks for info Yuval A. It would help if you would include your latest comment to the answer, since it is quite important part of it (IMHO). – bbaja42 Oct 17 '11 at 12:28
6
  1. Download the latest version of java from java.sun.com
  2. Extract the file in your home folder.
  3. Run the following commands in terminal

    sudo mkdir -p /usr/lib/java/

    sudo mv jdk1.7.0/ /usr/lib/java/

  4. Find the file profile in etc folder of FileSystem

  5. Edit in editor and write the line

    export PATH=/usr/lib/java/jdk1.7.0/bin:$PATH

  6. save it. You might need to restart your system to make these change.

You can check the current version using the following command javac -version

2

easiest way:

sudo add-apt-repository -y ppa:webupd8team/java

<p>sudo apt-get update</p>

<p>sudo apt-get install -y oracle-jdk7-installer</p>

I don't think you will need to bother setting the path after that.

Magpie
  • 1,285
1

JAVA CLASSPATH SETTING IN UBUNTU

sudo gedit etc/environment

enter your password

PATH=".:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

(already exist) just add below two lines (here i am using java6)

JAVA_HOME="/usr/lib/jvm/java-1.6.0-openjdk-i386"

CLASSPATH=".:/usr/lib/jvm/java-1.6.0-openjdk-i386/lib"

save that file and restart the system.