在 CentOS 上配置/使用 LibreOffice(常简称 LibOffice),常见场景包括:安装、中文支持、命令行使用、以及自动化/服务器环境配置。下面按“从安装到常用配置”逐步说明。
适用于大多数 CentOS 7 / CentOS Stream 8/9。
# CentOS 7
sudo yum install libreoffice -y
# CentOS 8 / Stream
sudo dnf install libreoffice -y
安装的组件包括:
查看版本:
libreoffice --version
适合需要新功能或修复旧版本 bug 的场景。
wget https://download.documentfoundation.org/libreoffice/stable/7.6.4/rpm/x86_64/LibreOffice_7.6.4_Linux_x86-64_rpm.tar.gz
版本号可按需替换
tar -zxvf LibreOffice_* .tar.gz
cd LibreOffice_* /RPMS
sudo yum localinstall *.rpm
sudo yum install wqy-zenhei-fonts wqy-microhei-fonts -y
或:
sudo yum install google-noto-sans-cjk-fonts -y
fc-cache -fv
locale
如果不是 zh_CN,可临时测试:
LANG=zh_CN.UTF-8 libreoffice --calc
常用于:
sudo yum install libreoffice-headless libreoffice-writer libreoffice-calc libreoffice-impress -y
libreoffice --headless --convert-to pdf test.docx
指定输出目录:
libreoffice --headless --convert-to pdf --outdir /tmp test.docx
如报表、宏、部分导出功能需要 Java。
sudo yum install java-11-openjdk -y
打开:
libreoffice
路径示例:
/opt/libreoffice7.6/program
export LIBREOFFICE_PATH=/usr/bin/libreoffice
echo 'export LIBREOFFICE_PATH=/usr/bin/libreoffice' >> ~/.bashrc
source ~/.bashrc
✅ 解决:
sudo yum install wqy-zenhei-fonts
fc-cache -fv
✅ 解决:
libreoffice --headless --norestore --invisible --convert-to pdf test.docx
✅ 限制并发或使用轻量替代(如 unoconv、pandoc)
| 需求 | 命令 |
|---|---|
| 安装 LibreOffice | yum install libreoffice |
| 转 PDF | libreoffice --convert-to pdf |
| 无界面运行 | --headless --norestore |
| 中文支持 | wqy-zenhei-fonts |
| 查看版本 | libreoffice --version |
如果你能告诉我:
我可以给你 定制化配置方案,甚至写自动化脚本。