我从链接http://www.oracle.com/technetwork/java/javase/downloads/index.html下载了jdk-9.0.1_linux-x64_bin.tar.gz和jre-9.0.1_linux-x64_bin.tar.gz。提取它们并在/ usr / local / java中进行抽取。然后编辑/ etc / profile添加
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
整个文件看起来像
# /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
然后 键入以下命令
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
现在java -version正在显示
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)
之后我尝试安装android studio
我收到以下消息
./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.
答案 0 :(得分:0)
尝试从
更改设置PATH变量的行PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin
收件人
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
这将使JDK的优先级高于JRE。
答案 1 :(得分:0)
我建议您卸载JRE安装并仅使用JDK安装。 JDK包含JRE中存在的所有内容。同时安装两者会浪费磁盘空间,并可能导致类似您遇到的问题。
卸载JRE时,请记住要更新环境变量。
还值得注意的是,通过像这样设置PATH,就避开了“替代”选择器。