【发布时间】:2025-12-04 10:25:01
【问题描述】:
我从链接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.
【问题讨论】:
-
不说jdk7,我用的是jdk9;两者都有不同的安装程序。他们添加了 /etc/environment 的路径。我正在从 /etc/profile 导出路径
-
我推荐在this tutorial 中提到的在linux 中安装java。请尝试不同的 Java 版本。我个人使用jdk8进行android开发
标签: java android installation