0

I'm trying to install JRE on Ubuntu 13.10. I followed this guide. When I run "java -version" it says "command not found"...

This is the result of "sudo find / -name java"

/var/lib/dpkg/alternatives/java
/usr/lib/jvm/java-7-oracle/bin/java
/usr/lib/jvm/java-7-oracle/jre/bin/java
/usr/lib/ure/share/java
/usr/local/java
/usr/local/java/jre1.7.0_51/bin/java
/usr/bin/java
/usr/java
Sionnach733
  • 4,686
  • 4
  • 36
  • 51
Stefano Nardo
  • 1,567
  • 2
  • 13
  • 23

2 Answers2

4

Basically command not found happens when you didn't set up the PATH of installed java.

This guide here covers more about how to install java on a ubuntu machine completely, but here I'm just going to present how to setup your java runnable:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_51/bin/java" 1
sudo chmod a+x /usr/bin/java 

and then

sudo update-alternatives --config java

Choose the one that has /usr/local/java/jre1.7.0_51/bin/java in the options.

Community
  • 1
  • 1
albusshin
  • 3,930
  • 3
  • 29
  • 57
  • it doesn't work... Now the error at java -version is: /usr/bin/java: 2: /usr/bin/java: Syntax error: newline unexpected (expecting ")") – Stefano Nardo Mar 05 '14 at 14:25
  • According to your comment of @Jay's answer, I think the installation of java is broken on your machine. Try to re-install it and test it again? – albusshin Mar 05 '14 at 16:14
1

You need to set your Java bin full path /jre1.7.0_51/bin to the PATH variable in your Shell window. Like this

        export PATH:$PATH:/jre1.7.0_51/bin

You can check the existing PATH by typing echo $PATH in your Shell window.

Jay
  • 9,189
  • 12
  • 56
  • 96
  • Do I have to type this on terminal? – Stefano Nardo Mar 05 '14 at 14:22
  • it doesn't modify the PATH... this is the error: PATH:/jre1.7.0_51/binbash: export: "PATH:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/jre1.7.0_51/bin": not a valid identifier – Stefano Nardo Mar 05 '14 at 14:26
  • Please type "echo $PATH" and paste the results. – Jay Mar 05 '14 at 14:31
  • /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games – Stefano Nardo Mar 05 '14 at 14:34
  • Ok this shows there is no java in your path. Now you need to type the full path of your java bin folder. For example "export PATH:$PATH:/usr/local/java/jre1.7.0_51/bin". Then try "echo $PATH" again it should include the java path. – Jay Mar 05 '14 at 14:37
  • Same error... Not a valid identifier and PATH without java – Stefano Nardo Mar 05 '14 at 14:41
  • You need to find the java installed location and give it correctly in the PATH. Try command "which java" to find the java location. – Jay Mar 05 '14 at 14:47
  • Which java returns /usr/bin/java. I tried to give it in the PATH but it returns the same error about identifier. By the way, the location you suggested me /usr/local/java/jre1.7.0_51/bin) it exists. EDIT: /usr/bin/java is not a directory, is it normal? – Stefano Nardo Mar 05 '14 at 14:53
  • I restarted PC and now my path is: "/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-7-oracle/jre/bin" but it still stays "file or directory does not exists" ... If I run java -version it returns: "/usr/bin/java: cannot execute binary file" – Stefano Nardo Mar 05 '14 at 15:17