Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
sachin@sachin-Lenovo-G550:~$ java -version
java version “1.7.0_21″
OpenJDK Runtime Environment (IcedTea 2.3.9) (7u21-2.3.9-1ubuntu1)
OpenJDK Server VM (build 23.7-b01, mixed mode)

When I ran the above command this showed that Java is installed in my system, but when I am going to compile any Java program it gives the following error message:

sachin@sachin-Lenovo-G550:~/programs$ javac
The program ‘javac’ can be found in the following packages:
* default-jdk
* ecj
* gcj-4.6-jdk
* gcj-4.7-jdk
* openjdk-7-jdk
* openjdk-6-jdk
Try: sudo apt-get install

Please tell me how to get rid of it and run my Java program.

share|improve this question

Open the terminal and run:

sudo apt-get install openjdk-7-jdk

and then compile your Java program as before with: javac Then run it with:

java abc  ## The name of the class to be called is abc NOT abc.class

You can also substitute openjdk-6-jdk instead of openjdk-7-jdk in the first command.

share|improve this answer

If you prefer to install Oracle JDK, a step by step instruction on installing Oracle JDK 8 is explained in this article : Install Latest Oracle JDK in Ubuntu

Step 1: Download the latest JDK(jdk-Xuxx-linux-xXX.tar.gz) from this official link.

Step 2: Open the terminal (Ctrl + Alt + T) and enter the following command.

sudo mkdir /usr/lib/jvm

Step 3: Enter the following command to change the directory.

cd /usr/lib/jvm

Step 4: Extract the jdk-Xuxx-linux-xXX.tar.gz file in that directory using this command.

sudo tar -xvzf ~/Downloads/jdk-8u45-linux-x64.tar.gz

Step 5: Enter the following command to open the environment variables file.

sudo gedit /etc/environment

Step 6: In the opened file, add the following bin folders to the existing PATH variable.


The PATH variables have to be separated by semicolon. Notice that the installed JDK version is 1.8 update 45. Depending on your JDK version, the paths can be different. Add the following environment variables at the end of the file.


The environment file before the modification:


The environment file after the modification:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.