Ubuntu – Setup JDK for android studio

androidjavajdkopenjdk

I was setting up android studio and got this

enter image description here

So I followed the answer here and used

sudo update-alternatives --set java /usr/local/java/jdk1.7.0_17/jre/bin/java

sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_17/jre/bin/javaws

But this gave me update-alternatives: error: alternative /usr/local/java/jdk1.7.0_17/jre/bin/java for java not registered; not setting

How can I fix this and get android studio working? I am have openJDK installed.

Best Answer

Most likely the exact 1.7.17 version is different now and the jdk1.7.0_17 does not exists, so use the interactive command to change the java or javaws alternative.

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode
* 1            /usr/lib/jvm/j2re1.7-oracle/bin/java             316       manual mode
  2            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
Press enter to keep the current choice[*], or type selection number: 1

$ sudo update-alternatives --config javaws
There are 3 choices for the alternative javaws (providing /usr/bin/javaws).
  Selection    Path                                              Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws   1071      auto mode
  1            /usr/lib/jvm/j2re1.7-oracle/bin/javaws             316       manual mode
  2            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws   1061      manual mode
  3            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws   1071      manual mode
Press enter to keep the current choice[*], or type selection number: 1

It's a lot less likely to make mistakes with this. :)

Related Question