Having just installed Java on the Pi, which in itself was virtually impossible, I have written some Java. Which will not compile. Having written the file, named hello.java, I type:

javac hello.java

into the LXTerminal. The folder which the file is in is /home/pi/Java and is set on the command line. At compilation I get this error:

bash: javac: command not found

can anyone help?

  • 2
    How did you install Java or which Java did you install? I installed openjdk using sudo apt-get install openjdk-6-jdk and javac is in my /usr/bin – HeatfanJohn Mar 2 '13 at 20:00
  • I couldnt find the right package with sudo apt-get... so i installed chromium browser and then downloaded java from this url: http://jdk8.java.net/fxpreview/index.html – imulsion Mar 3 '13 at 7:51

This is a $PATH issue. $PATH is an environment variable that contains a list of directories to search when looking for an executable. You can see your current $PATH via echo $PATH.

javac: command not found indicates javac is not in any of the directories in your $PATH. You need to add the directory with javac in it into your $PATH, or add javac to one of the directories in your $PATH -- but the former is much preferable.

To temporarily add a directory for your current shell:

export PATH=/some/directory:$PATH

If you want to use that permanently, add the same line to ~/.bashrc. For example, I use JDK 8 on the pi that I have installed to /usr/local, so I have a line:

export PATH=/usr/local/jdk1.8.0/bin:$PATH

That directory contains java, javac, jar, etc.

You mentioned that java appears in be in your path since "java -version comes up with the java number and package so java is definitely installed" although you do not actually say what that number and package are. I suspect you have multiple versions installed, one of which is just a jre and thus does not include javac.


It's likely you just installed the JRE and not the full JDK. If you're running Raspbian Wheezy, you can use

apt-get install openjdk-7-jdk

to install javac. (If you're using the older Debian Wheezy OS, it works with the Sun JVM, so you can install that with the instructions here: http://www.savagehomeautomation.com/pi-jdk . The standard Raspbian OS isn't supported by Sun yet, so you have to use Openjdk with it.)


Do you get anything with when typing 'java -version' in command line ? If not, it is not fully configured. Also, did you set the JAVA_HOME in your class path ?

SO Link Java ClassPath

Check the above link out for that, if you have not done so already.

  • no, i have not set any environment variables. how do i do this on the pi? java -version comes up with the java number and package so java is definitely installed – imulsion Mar 3 '13 at 7:55
  • if it a debian linux the link I provided should work. – ebel Mar 4 '13 at 2:09

javac: Command not found - after installing Java

If you receive this error, UNIX cannot find the compiler, javac. or javac: Command not found - after installing Java

Here's one way to tell UNIX where to find javac. Suppose you installed the JDK in /usr/local/jdk1.8.0. At the prompt you would type the following command and press Return:

/usr/local/jdk1.8.0/javac hello.java Note: If you choose this option, each time you compile or run a program, you'll have to precede your javac and java commands with /usr/local/jdk1.8.0/. To avoid this extra typing, you could add this information to your PATH variable. The steps for doing so will vary depending on which shell you are currently running.

Class names, 'hello', are only accepted if annotation processing is explicitly requested

If you receive this error, you forgot to include the .java suffix when compiling the program. Remember, the command is javac hello.java not javac hello.

For more details, consult this lecture "Creating a Hello World application" in this page. http://learnjavaeasy.com/course/learn-java-online-with-java-8-by-examples/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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