0

I downloaded jdk-9.0.1_linux-x64_bin.tar.gz and jre-9.0.1_linux-x64_bin.tar.gz from link http://www.oracle.com/technetwork/java/javase/downloads/index.html. extracted them and psasted in /usr/local/java. Then edited /etc/profile to add

JAVA_HOME=/usr/local/java/jdk-9.0.1
JRE_HOME=/usr/local/java/jre-9.0.1
PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

the whole file looks like

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

JAVA_HOME=/usr/local/java/jdk-9.0.1
JRE_HOME=/usr/local/java/jre-9.0.1
PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

then typed following commands

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-9.0.1/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk-9.0.1/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk-9.0.1/bin/javaws" 1 


sudo update-alternatives --set java /usr/local/java/jdk-9.0.1/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk-9.0.1/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jdk-9.0.1/bin/javaws

source /etc/profile

reboot

now java -version is showing

java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

after that I tried to install android studio

I get the following message

./studio.sh 
Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
WARN: Unknown class loader: jdk.internal.loader.ClassLoaders$AppClassLoader
WARN: Unknown class loader: jdk.internal.loader.ClassLoaders$PlatformClassLoader
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.lang.UrlClassLoader (file:/home/user/Downloads/Android/android-studio/lib/util.jar) to field java.lang.ClassLoader.parallelLockMap
WARNING: Please consider reporting this to the maintainers of com.intellij.util.lang.UrlClassLoader
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

JDK Required: 'tools.jar' seems to be not in Studio classpath.
Please ensure JAVA_HOME points to JDK rather than JRE.
ankit
  • 11
  • 5
  • possible duplicate: https://stackoverflow.com/questions/17474963/android-studio-tools-jar-file-is-not-present-in-classpath – no_fate Dec 25 '17 at 11:16
  • no that talks about jdk7, I am using jdk9; both have different installation procedures. They have added path to /etc/environment. I am exporting path from /etc/profile – ankit Dec 25 '17 at 11:35
  • I recommend installing java in linux as mentioned in [this tutorial](https://www.wikihow.com/Install-Oracle-Java-on-Ubuntu-Linux). Please try a different Java version. I personally use jdk8 for android development – Rosário Pereira Fernandes Dec 25 '17 at 14:02

2 Answers2

0

Try to change the line setting the PATH variable from

PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin

To

PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

That will give priority to the JDK over the JRE.

0

I recommend that you uninstall the JRE installation and just use JDK installations. The JDK contains everything that is present in the JRE. Installing both is a waste of disk space ... and potentially causes problems like the one you are experiencing.

When you uninstall the JRE, remember to update the environment variables.

It is also worth noting that by setting PATH like this, you are side-stepping the "alternatives" selector.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216