0

I'm new to Ubuntu and I have recently made my laptop dual boot Windows 8 and Ubuntu 12.04. I installed java by using the command

sudo apt-get install openjdk-7-jdk

It installed successfully. I tried compile java program it shows following message

a@ubuntu:~/Desktop$ javac hello.java
The program 'javac' can be found in the following packages:
* default-jdk
* ecj
* gcj-4.6-jdk
* openjdk-6-jdk
* gcj-4.5-jdk
* openjdk-7-jdk
Try: sudo apt-get install <selected package>

Please suggest what to do??? Thanks in advance..

Shashanth
  • 463
sahil
  • 1

1 Answers1

2

Looks like your jdk installation was proper and JAVA_HOME is not set as Environment variable. To set JAVA_HOME variable follow the below steps

  1. Open terminal (Ctrl + Alt + T )
  2. Edit the environment file using the command

    $ sudo gedit /etc/environment
    

    or you can use nano editor as your wish.

  3. At the end of the file paste the following lines

    JAVA_HOME="/usr/lib/jvm/open-jdk"
    export JAVA_HOME
    

    Note: The JAVA_HOME path depends on installtion path of jdk.

  4. Save the file and exit from gedit.

  5. Use the following command to reload Environment variable changes,

    $ source /etc/environment
    
  6. Now check the jdk path using the command

    $ echo $JAVA_HOME
    

or use

    $ java -version 

The above command will give you the installed jdk version if it's installed properly.

If it's not working reboot your system once.

For more info see this How to set JAVA_HOME for Java?

Shashanth
  • 463