Ubuntu 22.04 安装 Apache NetBeans 31 指南
在真实 Ubuntu 22.04 LTS 服务器上安装 Apache NetBeans 31 的完整指南,覆盖官方 zip、清华镜像与 snap 三种安装方案、JDK 21 前置、JVM 内存限制、版本验证、升级降级与卸载,均已在 Ubuntu 22.04.5 实测通过
Ubuntu 22.04 安装 Apache NetBeans 31 指南
目标:在真实 Ubuntu 22.04 LTS 服务器上从零安装 Apache NetBeans 31,本文提供官方 zip、清华镜像与 snap 三种安装方案、JDK 21 前置环境、安装布局与 JVM 内存限制配置、版本验证及排障方法,所有命令与回显均在 Ubuntu 22.04.5(amd64)上实测通过。
一、环境信息
- 操作系统:Ubuntu 22.04.5 LTS(Jammy Jellyfish),内核
6.8.0-138-generic - CPU 架构:amd64(x86_64)
- CPU 核数:12
- 内存:31 GiB
- JDK:OpenJDK 21.0.12.1(
openjdk-21-jdk-headless),路径/usr/lib/jvm/java-21-openjdk-amd64 - NetBeans:Apache NetBeans 31(
build_info编号31-f8ac37e0f2434a7f000fbe3360f1a92aa3ea67bc,2026-08-05 构建),安装目录/opt/netbeans(约 994M) - 发行包:
netbeans-31-bin.zip(497M) - 默认用户目录:
/root/.netbeans/31;默认缓存目录:/root/.cache/netbeans/31
二、前置条件
Apache NetBeans 31 是运行在 JVM 上的 IDE,最低要求 Java 21。先安装 JDK 与基础工具:
sudo apt-get update && sudo apt-get install -y openjdk-21-jdk-headless wget unzip
验证 Java 是否可用:
java -version
实测回显:
openjdk version "21.0.12.1" 2026-08-18
OpenJDK Runtime Environment (build 21.0.12.1+1-1-22.04.4-Ubuntu)
OpenJDK 64-Bit Server VM (build 21.0.12.1+1-1-22.04.4-Ubuntu, mixed mode, sharing)
⚠️ 注意:NetBeans 31 在 Java 21 以下版本无法启动。实测使用 JDK 17(
--jdkhome指向/usr/lib/jvm/java-17-openjdk-amd64)启动时直接报错退出(退出码 10):Cannot run on older versions of Java than Java 21. Please install Java 21 or newer or use --jdkhome
三、安装方案 A:官方 zip 安装(推荐)
3.1 方案说明
Apache 官方以 zip 分发 Linux/通用版 NetBeans,不依赖系统包管理器,可精确锁定 31 版本、便于多版本共存,适合服务器统一部署。目录统一放到 /opt。
3.2 下载
官方当前版本目录:https://dlcdn.apache.org/netbeans/netbeans/31/。切换到 /opt 并下载:
cd /opt
wget https://dlcdn.apache.org/netbeans/netbeans/31/netbeans-31-bin.zip
国内网络可改用清华镜像下载同一文件(见方案 B 校验值,两源文件一致)。
3.3 sha512 校验
取官方校验文件并比对:
wget -O - https://dlcdn.apache.org/netbeans/netbeans/31/netbeans-31-bin.zip.sha512
sha512sum netbeans-31-bin.zip
实测两行输出一致:
108edccc78075b0bc87e3e055170fd03c17442cd1748b68297b49ebe003f8fa5cc7cb265c2fbbe2d5c802d0b29fe5654b89a78a8fd92b784147a7a982f1a42df ./netbeans-31-bin.zip
108edccc78075b0bc87e3e055170fd03c17442cd1748b68297b49ebe003f8fa5cc7cb265c2fbbe2d5c802d0b29fe5654b89a78a8fd92b784147a7a982f1a42df netbeans-31-bin.zip
3.4 解压安装
cd /opt
unzip -q netbeans-31-bin.zip
确认目录生成:
ls -ld /opt/netbeans
实测回显:
drwxr-xr-x 21 root root 4096 Aug 5 13:05 /opt/netbeans
3.5 安装布局确认
ls /opt/netbeans
实测回显:
DEPENDENCIES LICENSE NOTICE README.html apisupport bin cpplite enterprise ergonomics etc extide groovy harness ide java javafx licenses nb netbeans.css php platform profiler webcommon websvccommon
关键目录与文件:
bin/netbeans:Linux 启动器脚本(唯一的命令行入口);etc/netbeans.conf:全局启动配置(用户目录、JVM 参数、JDK 路径);etc/netbeans.clusters:模块簇加载顺序清单;platform/、ide/、java/等:按功能划分的模块簇(cluster)目录。
3.6 配置命令行入口
创建环境变量文件,把启动器加入 PATH:
echo 'export NETBEANS_HOME=/opt/netbeans' > /etc/profile.d/netbeans.sh
echo 'export PATH=$NETBEANS_HOME/bin:$PATH' >> /etc/profile.d/netbeans.sh
让当前 shell 立即生效:
source /etc/profile.d/netbeans.sh
which netbeans
回显应为 /opt/netbeans/bin/netbeans。
3.7 验证安装
执行帮助命令(无需图形界面即可运行):
netbeans --help
实测回显:
Usage: /opt/netbeans/platform/lib/nbexec {options} arguments
General options:
--help show this help
--jdkhome <path> path to Java(TM) 2 SDK, Standard Edition
-J<jvm_option> pass <jvm_option> to JVM
--cp:p <classpath> prepend <classpath> to classpath
--cp:a <classpath> append <classpath> to classpath
/opt/netbeans/platform/lib/nbexec: WARNING: environment variable DISPLAY is not set
WARNING: package com.sun.java.swing.plaf.windows not in java.desktop
WARNING: package com.apple.laf not in java.desktop
netbeans.user points to a non-existent directory.
Module reload options:
--reload /path/to/module.jar install or reinstall a module JAR file
Additional module options:
--modules
--refresh Refresh all catalogs
--list Prints the list of all modules, their versions and enablement status
--install <arg1>...<argN> Installs provided JAR files as modules
--disable <arg1>...<argN> Disable modules for specified codebase names
--enable <arg1>...<argN> Enable modules for specified codebase names
--update <arg1>...<argN> Updates all or specified modules
--update-all Updates all modules
--extra-uc <arg> Add a extra Update Center (URL)
--direct-disable <arg1>...<argN> Disable module immediately
--start-java-language-server [<arg>] Starts the Java Language Server
--start-java-debug-adapter-server [<arg>] Starts the Java Debug Adapter Server
--open file1[:line1]... open specified file(s), possibly at given location; can also pass project directories
--open-group NAME open a project group by shortened or full name (or unique substring)
--close-group close any open project group
--list-groups list available project groups
Core options:
--laf <LaF classname> use given LookAndFeel class instead of the default
--fontsize <size> set the base font size of the user interface, in points
--locale <language[:country[:variant]]> use specified locale
--userdir <path> use specified directory to store user settings
--cachedir <path> use specified directory to store user cache, must be different from userdir
--nosplash do not show the splash screen
⚠️ 注意:
WARNING: environment variable DISPLAY is not set在无桌面的服务器上属正常现象,--help等命令行功能不受影响;NetBeans 图形界面的启动需要桌面环境(X Window System),GUI 相关操作见《Apache NetBeans 31 项目开发实践指南》的 ⚠️ 前置说明。
查看构建信息确认版本:
cat /opt/netbeans/nb/build_info
实测回显:
NetBeans dev build
------------------
Number: 31-f8ac37e0f2434a7f000fbe3360f1a92aa3ea67bc
Date: 5 Aug 2026
Branding:
Branch: trunk
Tag:
Hg ID: unknown-revn
首次运行任一命令(如 netbeans --modules --list)后,用户目录下的运行日志会记录完整的运行环境信息:
grep "Product Version" /root/.netbeans/31/var/log/messages.log
实测回显:
Product Version = Apache NetBeans IDE 31
四、安装方案 B:清华镜像下载(国内加速)
4.1 方案说明
与方案 A 完全相同的官方 zip,改由清华大学开源软件镜像站分发,适合国内服务器直连官方源较慢的场景。安装步骤与方案 A 的 3.4~3.7 一致,仅下载源不同。
4.2 下载与校验
cd /opt
wget https://mirrors.tuna.tsinghua.edu.cn/apache/netbeans/netbeans/31/netbeans-31-bin.zip
实测文件列表:
-rw-r--r-- 1 root root 497M Aug 5 15:08 netbeans-31-bin.zip
校验(校验值应与方案 A 完全一致):
sha512sum netbeans-31-bin.zip
实测回显:
108edccc78075b0bc87e3e055170fd03c17442cd1748b68297b49ebe003f8fa5cc7cb265c2fbbe2d5c802d0b29fe5654b89a78a8fd92b784147a7a982f1a42df netbeans-31-bin.zip
五、安装方案 C:snap 安装(Ubuntu)
5.1 方案说明
Ubuntu 22.04 可通过 snap 商店安装 NetBeans(classic 接管),由 snap 自动管理升级。⚠️ 前置要求:需要已启用 systemd 与 snapd 的 Ubuntu 系统(桌面版与服务器版均满足;最小化安装的系统需先安装 snapd)。
5.2 安装 snapd 并启动服务
sudo apt-get install -y snapd
sudo systemctl enable --now snapd.socket
sudo systemctl start snapd.service
确认 snap 可用:
snap version
实测回显:
snap 2.76.3+ubuntu22.04.1
snapd 2.76.3+ubuntu22.04.1
series 16
ubuntu 22.04
kernel 6.8.0-138-generic
architecture amd64
5.3 安装 NetBeans
sudo snap install netbeans --classic
实测回显:
2026-10-11T15:07:16Z INFO Waiting for automatic snapd restart...
2026-10-11T15:07:17Z INFO Waiting for automatic snapd restart...
2026-10-11T15:07:18Z INFO Waiting for automatic snapd restart...
Warning: /snap/bin was not found in your $PATH. If you've not restarted your
session since you installed snapd, try doing that. Please see
https://forum.snapcraft.io/t/9469 for more details.
netbeans 31 from Apache NetBeans** installed
💡 说明:
/snap/bin was not found in your $PATH警告出现在首次安装 snapd 后,重新登录会话(或执行hash -r)即可消除;--classic是 NetBeans 对整系统的访问授权,必加。
5.4 验证安装
snap list netbeans
ls -la /snap/bin/netbeans
实测回显:
Name Version Rev Tracking Publisher Notes
netbeans 31 149 latest/stable apache-netbeans** classic
lrwxrwxrwx 1 root root 13 Oct 11 15:08 /snap/bin/netbeans -> /usr/bin/snap
六、多方案对比与选择建议
| 对比项 | 方案 A:官方 zip | 方案 B:清华镜像 zip | 方案 C:snap |
|---|---|---|---|
| 版本 | 精确 31(build_info 可查) | 与官方一致(sha512 相同) | 31(Rev 149,随 stable 通道升级) |
| 是否需联网下载 | 是(dlcdn.apache.org) | 是(mirrors.tuna.tsinghua.edu.cn) | 是(snap 商店) |
| 安装方式 | wget + unzip 到 /opt | 同 A | snapd 包管理 |
| 多版本共存 | 支持(目录级隔离) | 支持 | 不支持(单版本) |
| 升级方式 | 下载新 zip 重新解压 | 同 A | snap refresh 自动/手动 |
| 适用场景 | 生产服务器、版本敏感 | 国内网络加速 | 桌面/开发机快速安装 |
选择建议:服务器统一部署、需要锁定版本或多版本共存选方案 A/B(内网或国内网络优先 B);个人开发机求省事选 C。
七、安装后基础配置
7.1 指定 JDK 路径
编辑 /opt/netbeans/etc/netbeans.conf,取消注释并设置 netbeans_jdkhome:
netbeans_jdkhome="/usr/lib/jvm/java-21-openjdk-amd64"
重启 NetBeans 后,在用户目录日志中确认生效:
grep "Java Home" /root/.netbeans/31/var/log/messages.log
实测回显:
Java Home = /usr/lib/jvm/java-21-openjdk-amd64
7.2 限制 JVM 堆内存
NetBeans 默认堆大小由 JVM 自动选择(可在 var/log/messages.log 查看),服务器与其他服务混部时建议显式限制。在 /opt/netbeans/etc/netbeans.conf 的 netbeans_default_options 中追加(或临时在命令行透传):
netbeans -J-Xms256m -J-Xmx512m --modules --list
对正在运行的 NetBeans 进程用 jcmd 验证实际生效堆:
jcmd $(pgrep -x java | head -1) VM.flags | tr ' ' '\n' | grep -E 'MaxHeapSize=|InitialHeapSize=' | awk -F= '{printf "%s = %.0f MB\n", $1, $2/1048576}'
实测回显:
-XX:InitialHeapSize = 256 MB
-XX:MaxHeapSize = 512 MB
-XX:SoftMaxHeapSize = 512 MB
7.3 用户目录与缓存目录
首次运行后 NetBeans 自动创建用户目录与缓存目录,实测默认位置:
ls /root/.netbeans/
ls /root/.cache/netbeans/
实测回显:
31
31
即默认用户目录 ~/.netbeans/31(配置、日志)、默认缓存目录 ~/.cache/netbeans/31。详见《Apache NetBeans 31 配置参数详解》。
八、升级、降级与多版本管理
8.1 升级(zip 方案)
下载新版 zip 解压到 /opt,替换 NETBEANS_HOME 指向,并把 /etc/profile.d/netbeans.sh 中的路径同步修改:
cd /opt
wget https://dlcdn.apache.org/netbeans/netbeans/<新版本号>/netbeans-<新版本号>-bin.zip
unzip -q netbeans-<新版本号>-bin.zip
sed -i 's#export NETBEANS_HOME=.*#export NETBEANS_HOME=/opt/netbeans-<新版本号>#' /etc/profile.d/netbeans.sh
source /etc/profile.d/netbeans.sh
netbeans --help
💡 说明:
<新版本号>用curl -s https://dlcdn.apache.org/netbeans/netbeans/ | grep -oE '"[0-9]+/"'查询当前发布版本,不做硬编码。
8.2 降级与多版本共存
历史版本从 Apache 归档站获取:https://archive.apache.org/dist/netbeans/netbeans/。不同版本解压到不同目录(如 /opt/netbeans-27),通过完整路径调用:
/opt/netbeans-27/bin/netbeans --help
各版本用户目录按版本号隔离(~/.netbeans/<版本>),互不干扰。旧版配置可随首次启动自动导入(用户目录内的 var/imported 目录记录导入痕迹)。
8.3 snap 方案升级/回退
sudo snap refresh netbeans # 升级到 stable 最新
sudo snap refresh --revision=<旧Rev> netbeans # 回退到指定修订
九、常见问题
Q1:启动报 Cannot run on older versions of Java than Java 21.
系统的 java 不是 21+ 或 netbeans_jdkhome 指向了旧 JDK。安装 openjdk-21-jdk-headless 后,在 /opt/netbeans/etc/netbeans.conf 设置 netbeans_jdkhome="/usr/lib/jvm/java-21-openjdk-amd64",或启动时临时指定 netbeans --jdkhome /usr/lib/jvm/java-21-openjdk-amd64。
Q2:执行 netbeans --list 报 Need to use also --modules, --refresh
--list 是模块清单选项,必须与 --modules 组合使用:netbeans --modules --list(退出码 173 也属该场景的实测现象)。
Q3:无桌面服务器上启动图形界面失败 / 出现 DISPLAY is not set
NetBeans GUI 需要 X Window 桌面环境;无桌面服务器仅支持 --help、--modules 系列等命令行功能,此为正常行为。需要远程使用 GUI 时,为服务器配置 X11 转发(ssh -X)或 VNC 桌面后再启动 netbeans。
Q4:--help 输出里 netbeans.user points to a non-existent directory. 是错误吗
首次运行前用户目录尚未创建,属正常提示;首次完整运行(如 netbeans --modules --list)后即自动创建 ~/.netbeans/31。
Q5:sha512 校验不一致
确认下载的是 netbeans-31-bin.zip(二进制发行包)而非 netbeans-31-source.zip(源码包);重新下载后比对,仍不一致则更换镜像源。
十、卸载与清理
10.1 卸载 zip 方案(A/B)
删除安装目录与环境变量文件:
rm -rf /opt/netbeans
rm -f /etc/profile.d/netbeans.sh
清理用户目录与缓存(按需,会删除个人配置与日志):
rm -rf /root/.netbeans /root/.cache/netbeans
10.2 卸载 snap 方案(C)
sudo snap remove netbeans
用户数据同样在 ~/.netbeans/31 与 ~/.cache/netbeans/31,按需清理。
十一、参考链接
- Apache NetBeans 官方下载页:
https://netbeans.apache.org/download/ - 官方当前版本目录:
https://dlcdn.apache.org/netbeans/netbeans/31/ - 历史版本归档:
https://archive.apache.org/dist/netbeans/netbeans/ - 清华镜像 NetBeans 目录:
https://mirrors.tuna.tsinghua.edu.cn/apache/netbeans/ - snap 商店页面:
https://snapcraft.io/netbeans - 官方使用文档:
https://netbeans.apache.org/kb/docs/