在 Debian 上“Java 配置慢”通常表现在几个方面:软件源慢、apt 安装慢、Java 启动慢、环境变量配置复杂。下面分场景给你优化方案。
编辑:
sudo nano /etc/apt/sources.list
示例(清华源):
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free
然后:
sudo apt update
sudo apt install default-jdk
或指定版本:
sudo apt install openjdk-17-jdk
查看已安装:
update-alternatives --list java
Java 启动慢常因 /dev/random 阻塞:
sudo apt install haveged
sudo systemctl enable haveged
或 JVM 参数:
-Djava.security.egd=file:/dev/./urandom
如果是开发/服务:
sudo nano /etc/profile.d/java.sh
内容:
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$JAVA_HOME/bin:$PATH
生效:
source /etc/profile
time java -version
如果 > 2s,基本是熵池问题。
sudo apt update
sudo apt install -y openjdk-17-jdk haveged
sudo systemctl enable haveged
如果你能说清楚:
我可以给你更精准的方案。