Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a java computer program that I can compile in Eclipse just fine. I want to compile it from the command line and get the message javac not found. I figured that I just didn't have my path setup right, but then I did a locate javac and I only get:

/usr/share/bash-completion/completions/javac
/usr/share/vim/vim74/compiler/javac.vim
/usr/share/vim/vim74/syntax/javacc.vim

and it does not exist in

/usr/lib/jvm/java-7-openjdk-amd64/bin/

In Eclipse, it looks like it is using this JDK, so I am not sure how to account for how Eclipse compiles. Am I missing something silly? Thanks.

share|improve this question
1  
what is the output of 'javac -version' in the terminal? –  ganezdragon May 24 at 7:54
    
That is just the problem - it can't find the command. But Eclipse must be using it somewhere, right? –  skaz May 24 at 11:11
1  
I think Eclipse comes with a inbuilt compiler... so you might want to install jdk manually to run Java programs using the terminal. –  ganezdragon May 24 at 11:21
    
Try sudo apt-get install openjdk-7-jdk. –  saiarcot895 May 24 at 13:30

3 Answers 3

The default Java runtime environment (JRE) on Ubuntu is OpenJDK (instead of Oracle/Sun). Unlike the name OpenJDK this comes as two parts: a JRE (default-jre) and a JDK (default-jdk).

To also install the JDK (providing javac), install the metapackage default-jdk Install default-jdk and you should be all set.

In case you have more than one Java runtime or Java compiler installed, select the right one with update-alternatives:

sudo update-alternatives --config java   # runtime
sudo update-alternatives --config javaws # runtime Web Start (applets)
sudo update-alternatives --config javac  # compiler
share|improve this answer

It seems like the openjdk you are using isn`t a jdk(besides the name). It is just a jvm (it can run java programs but not compile them).

My solution was download the jdk from oracle site: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

(this link is for jdk7, if you need another version just look for jdk in the site).

share|improve this answer

It looks like my default install came with some weird version of Java - not the OpenJDK but even another version. I did an aptitude install to get the openjdk-7 and then everything worked fine.

I was confused because Eclipse compiled without a javac on the system, but I guess Eclipse has some tools inside that allow it to compile.

share|improve this answer

Your Answer

 
discard

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.