2

I was installing JDK7 on Ubuntu 12.04 by following the guide posted on web8. The commands posted in the guide were:

sudo mkdir -p  /usr/lib/jvm/ #just in case
sudo mv java-7-oracle/ /usr/lib/jvm/
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install update-java
sudo update-java

Till here everything went well. So hopefully jdk was installed correctly, but then when I tried to check the java version with the command:

java -version

...it gave me this error:

bash: /usr/bin/java: Permission denied

Yes i know this is a permission related issue. And it can be solved using the sudo command, but can someone tell the exact command? I also checked permissions using ls -l command and the output was:

-rw------- 1 ankit ankit   5650 Jun 27  2011 java  
-rw------- 1 ankit ankit   5805 Jun 27  2011 javac

None of the tutorials and videos i saw were having this issue why is it only me?have i messed up with some default configurations? do i need to change the permission to the /usr/ directory evrytime?

I know this may sound stupid to many here, but i really want to know exactly where I am going wrong.

2 Answers 2

5

Probably the execution flag is not true on this java script.
Try executing sudo chmod +x /usr/bin/java and see if the permission is back.

If that solved the issue, do the same for /usr/bin/javac.

6
  • yes it did solve. But on a more general basis,do we need not do this for all executables? And why was the execute flag not set by default at the time of installation? May 6, 2012 at 5:44
  • 1
    @ankitkhedekar: Executables downloaded from somewhere else may not have execution rights for "current" user by default, hence it is necessary to add executing rights in order to run them.
    – Kushal
    May 6, 2012 at 5:49
  • @Kush:thank you,i had never previously needed to do this for any installations, this was the first time. May 6, 2012 at 6:02
  • @Kush:one more thing how do i change the permission for all the files of a folder.the java/bin folder has many executable and i need to execute many of them. May 6, 2012 at 6:11
  • @ankitkhedekar: First, navigate to your java/bin directory from terminal, then run sudo chmod +x * (* is wildcard which mentions to consider all the files in a directory). As you said you haven't perform any installations this way is because Oracle has changed the licensing terms of distributing JDK, and hence it is not available and maintained in Ubuntu repositories, while you can use OpenJDK 7 instead of Oracle JDK but in that case, you may want to check here.
    – Kushal
    May 6, 2012 at 7:30
2

Following the same website, it now maintains a PPA for stable Oracle JDK7 which you can install using following ways.

First and foremost, follow the same source which suggests how to remove manually installed JDK and revert back the changes.

Then, add PPA for JDK7 as follows,

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get-update
sudo apt-get install oracle-jdk7-installer

Than, this will pull the latest version of JDK7 from Oracle and also will keep you up-to-date with JDK.

You can find out official guide from WebUpd8.org here.

WebUpd8.org is great source by the way, you can check out other PPAs it maintains here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .