Linux 安装 LibreOffice

LibreOffice是由文档基金会开发的自由及开放源代码的办公室套件。LibreOffice套件包含文字处理器、电子表格、演示文稿程序、矢量图形编辑器和图表工具、数据库管理程序及创建和编辑数学公式的应用程序。

Section1、下载LibreOffice

到LibreOffice官网进行下载

download-libreoffice

如上图所示选择操作系统类型为Linux(64-bit)(rpm),然后下载 7.0.6 LTS 版本,然后上传到服务。如果您不想这么操作,可以在跳转的下载页面复制下载链接到服务器上使用wget工具进行下载,都是可以的,怎么方便怎么来嘛~

download-libreoffice-link

1
bash-4.4# wget https://download.documentfoundation.org/libreoffice/stable/7.0.6/rpm/x86_64/LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz

下载后的LibreOffice软件RPM安装如下所示:

1
2
3
bash-4.4# ll -h
总用量 251M
-rw-r--r-- 1 root root 251M 5月   7 19:37 LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz

Section2、下载内建帮助RPM包

1
bash-4.4# tar -zxvf LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz

解压后的目录结构如下,会将 LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz 归案文件解压到 LibreOffice_7.0.6.2_Linux_x86-64_rpm 目录。

1
2
3
4
bash-4.4# ll -h
总用量 251M
drwxr-xr-x 4 root root 4.0K 5月   7 11:03 LibreOffice_7.0.6.2_Linux_x86-64_rpm
-rw-r--r-- 1 root root 251M 5月   7 19:37 LibreOffice_7.0.6_Linux_x86-64_rpm.tar.gz

Section3、下载中文相关RPM包

首先进入到LibreOffice_7.0.6.2_Linux_x86-64_rpm目录

1
bash-4.4# cd LibreOffice_7.0.6.2_Linux_x86-64_rpm

您会看到类似如下的目录结构

1
2
3
4
5
bash-4.4# ll -h
总用量 20K
-rwxr-xr-x 1 root root  11K 5月   7 11:03 install
drwxr-xr-x 2 root root 4.0K 5月   7 11:03 readmes
drwxrwxr-x 2 root root 4.0K 5月   7 11:03 RPMS

进入到 RPMS 目录

1
bash-4.4# cd RPMS/

你会到下有许多RPM安装包

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
bash-4.4# ll -h
总用量 254M
-rw-r--r-- 1 root root 1.9M 5月   7 10:59 libobasis7.0-base-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 9.5M 5月   7 10:59 libobasis7.0-calc-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 103M 5月   7 10:58 libobasis7.0-core-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 6.2K 5月   7 11:00 libobasis7.0-draw-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root  89K 5月   7 10:59 libobasis7.0-en-US-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 394K 5月   7 11:03 libobasis7.0-extension-beanshell-script-provider-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 626K 5月   7 11:00 libobasis7.0-extension-javascript-script-provider-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.2M 5月   7 11:00 libobasis7.0-extension-mediawiki-publisher-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 1.2M 5月   7 11:02 libobasis7.0-extension-nlpsolver-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 1.1M 5月   7 11:03 libobasis7.0-extension-pdf-import-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 3.2M 5月   7 10:58 libobasis7.0-extension-report-builder-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 3.4M 5月   7 10:58 libobasis7.0-firebird-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 806K 5月   7 11:01 libobasis7.0-gnome-integration-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 1.7M 5月   7 10:58 libobasis7.0-graphicfilter-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root  48M 5月   7 10:59 libobasis7.0-images-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 748K 5月   7 11:01 libobasis7.0-impress-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.3M 5月   7 10:59 libobasis7.0-kde-integration-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 227K 5月   7 11:00 libobasis7.0-librelogo-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 3.6K 5月   7 11:03 libobasis7.0-libreofficekit-data-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 541K 5月   7 11:01 libobasis7.0-math-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 125K 5月   7 10:58 libobasis7.0-ogltrans-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 217K 5月   7 11:01 libobasis7.0-onlineupdate-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root  31M 5月   7 11:03 libobasis7.0-ooofonts-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.6K 5月   7 11:01 libobasis7.0-ooolinguistic-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 1.5M 5月   7 11:03 libobasis7.0-postgresql-sdbc-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root  14K 5月   7 11:01 libobasis7.0-python-script-provider-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 7.8M 5月   7 11:01 libobasis7.0-pyuno-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 4.9M 5月   7 10:59 libobasis7.0-writer-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 457K 5月   7 11:00 libobasis7.0-xsltfilter-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 755K 5月   7 10:59 libreoffice7.0-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.3K 5月   7 10:59 libreoffice7.0-base-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.3K 5月   7 11:01 libreoffice7.0-calc-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 6.3M 5月   7 11:03 libreoffice7.0-dict-en-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 1.4M 5月   7 11:01 libreoffice7.0-dict-es-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.2M 5月   7 11:03 libreoffice7.0-dict-fr-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.3K 5月   7 10:59 libreoffice7.0-draw-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 7.3K 5月   7 10:50 libreoffice7.0-en-US-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.5M 5月   6 18:41 libreoffice7.0-freedesktop-menus-7.0.6-2.noarch.rpm
-rw-r--r-- 1 root root 2.3K 5月   7 10:58 libreoffice7.0-impress-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.3K 5月   7 11:03 libreoffice7.0-math-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root  17M 5月   7 10:59 libreoffice7.0-ure-7.0.6.2-2.x86_64.rpm
-rw-r--r-- 1 root root 2.3K 5月   7 10:59 libreoffice7.0-writer-7.0.6.2-2.x86_64.rpm

Section3.1、下载内建帮助RPM包

返回到之前下载LibreOffice跳转的页面

download-libreoffice-link-help

复制 LibreOffice built-in help 下载链接地址,到Linux服务器还是之前的 RPMS 目录下去下载内建的帮助RPM安装包

1
wget https://download.documentfoundation.org/libreoffice/stable/7.0.6/rpm/x86_64/LibreOffice_7.0.6_Linux_x86-64_rpm_helppack_zh-CN.tar.gz

下载成功后会多出一个归案文件如下所示

1
2
bash-4.4# ll -l | grep tar.gz
-rw-r--r-- 1 root root   3995067 5月   7 19:37 LibreOffice_7.0.6_Linux_x86-64_rpm_helppack_zh-CN.tar.gz

将其解压

1
2
3
4
bash-4.4# tar -zxvf LibreOffice_7.0.6_Linux_x86-64_rpm_helppack_zh-CN.tar.gz
LibreOffice_7.0.6.2_Linux_x86-64_rpm_helppack_zh-CN/
LibreOffice_7.0.6.2_Linux_x86-64_rpm_helppack_zh-CN/RPMS/
LibreOffice_7.0.6.2_Linux_x86-64_rpm_helppack_zh-CN/RPMS/libobasis7.0-zh-CN-help-7.0.6.2-2.x86_64.rpm

然后将解压后的RPM包移动到当前目录

1
bash-4.4# mv LibreOffice_7.0.6.2_Linux_x86-64_rpm_helppack_zh-CN/RPMS/* .

Section3.2、下载中文语言RPM包

返回到之前下载LibreOffice跳转的页面

download-libreoffice-link-help

复制 Translated User Interface 下载链接地址,到Linux服务器还是之前的 RPMS 目录下去下载中文语言RPM安装包

1
bash-4.4# wget https://download.documentfoundation.org/libreoffice/stable/7.0.6/rpm/x86_64/LibreOffice_7.0.6_Linux_x86-64_rpm_langpack_zh-CN.tar.gz

下载成功后会多出一个归案文件LibreOffice_7.0.6_Linux_x86-64_rpm_langpack_zh-CN.tar.gz如下所示

1
2
3
bash-4.4# ll -l | grep tar.gz
-rw-r--r-- 1 root root   3995067 5月   7 19:37 LibreOffice_7.0.6_Linux_x86-64_rpm_helppack_zh-CN.tar.gz
-rw-r--r-- 1 root root    847058 5月   7 19:37 LibreOffice_7.0.6_Linux_x86-64_rpm_langpack_zh-CN.tar.gz

将其解压

1
2
3
4
5
bash-4.4# tar -zxvf LibreOffice_7.0.6_Linux_x86-64_rpm_langpack_zh-CN.tar.gz
LibreOffice_7.0.6.2_Linux_x86-64_rpm_langpack_zh-CN/
LibreOffice_7.0.6.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/
LibreOffice_7.0.6.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/libobasis7.0-zh-CN-7.0.6.2-2.x86_64.rpm
LibreOffice_7.0.6.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/libreoffice7.0-zh-CN-7.0.6.2-2.x86_64.rpm

然后将解压后的RPM包移动到当前目录

1
bash-4.4# mv LibreOffice_7.0.6.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/* .

Section4、安装LibreOffice

还是在 RPMS 目录执行以下命令进行LibreOfficeRPM安装包的安装

1
bash-4.4# su -c 'yum install *.rpm'

Section5、验证安装及修复相关依赖

1
2
bash-4.4# libreoffice7.0 -h
/opt/libreoffice7.0/program/soffice.bin: error while loading shared libraries: libcairo.so.2: cannot open shared object file: No such file or directory

你会发现它并没有给出相关的命令提示帮助信息而是报了个错,libcairo.so 这个动态链接库找不到,执行以下YUM命令进行安装

1
bash-4.4# yum install -y cairo

再次执行LibreOffice相关命令进行验证

1
2
bash-4.4# libreoffice7.0 -h
/opt/libreoffice7.0/program/soffice.bin: error while loading shared libraries: libcups.so.2: cannot open shared object file: No such file or directory

依然报错说 libcups.so 这个动态链接库找不到,执行以下YUM命令进行安装

1
bash-4.4# yum install -y cups-libs

再次执行LibreOffice相关命令进行验证

1
2
bash-4.4# libreoffice7.0 -h
/opt/libreoffice7.0/program/soffice.bin: error while loading shared libraries: libSM.so.6: cannot open shared object file: No such file or directory

还是报错说 libSM.so 这个动态链接库找不到,执行以下YUM命令进行安装

1
bash-4.4# yum install -y libSM

再次执行LibreOffice相关命令进行验证

1
2
bash-4.4# libreoffice7.0 -h
/opt/libreoffice7.0/program/soffice.bin: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

还是报错说 libX11-xcb.so 这个动态链接库找不到,执行以下YUM命令进行安装

1
bash-4.4# yum install -y libX11-xcb

再次执行LibreOffice相关命令进行验证,这次终于出来了!

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
bash-4.4# libreoffice7.0 -h
LibreOffice 7.0.6.2 144abb84a525d8e30c9dbbefa69cbbf2d8d4ae3b

Usage: soffice [argument...]
       argument - switches, switch parameters and document URIs (filenames).

Using without special arguments:
Opens the start center, if it is used without any arguments.
   {file}              Tries to open the file (files) in the components
                       suitable for them.
   {file} {macro:///Library.Module.MacroName}
                       Opens the file and runs specified macros from
                       the file.

Getting help and information:
   --help | -h | -?    Shows this help and quits.
   --helpwriter        Opens built-in or online Help on Writer.
   --helpcalc          Opens built-in or online Help on Calc.
   --helpdraw          Opens built-in or online Help on Draw.
   --helpimpress       Opens built-in or online Help on Impress.
   --helpbase          Opens built-in or online Help on Base.
   --helpbasic         Opens built-in or online Help on Basic scripting
                       language.
   --helpmath          Opens built-in or online Help on Math.
   --version           Shows the version and quits.
   --nstemporarydirectory
                       (MacOS X sandbox only) Returns path of the temporary
                       directory for the current user and exits. Overrides
                       all other arguments.

General arguments:
   --quickstart[=no]   Activates[Deactivates] the Quickstarter service.
   --nolockcheck       Disables check for remote instances using one
                       installation.
   --infilter={filter} Force an input filter type if possible. For example:
                       --infilter="Calc Office Open XML"
                       --infilter="Text (encoded):UTF8,LF,,,"
   --pidfile={file}    Store soffice.bin pid to {file}.
   --display {display} Sets the DISPLAY environment variable on UNIX-like
                       platforms to the value {display} (only supported by a
                       start script).

User/programmatic interface control:
   --nologo            Disables the splash screen at program start.
   --minimized         Starts minimized. The splash screen is not displayed.
   --nodefault         Starts without displaying anything except the splash
                       screen (do not display initial window).
   --invisible         Starts in invisible mode. Neither the start-up logo nor
                       the initial program window will be visible. Application
                       can be controlled, and documents and dialogs can be
                       controlled and opened via the API. Using the parameter,
                       the process can only be ended using the taskmanager
                       (Windows) or the kill command (UNIX-like systems). It
                       cannot be used in conjunction with --quickstart.
   --headless          Starts in "headless mode" which allows using the
                       application without GUI. This special mode can be used
                       when the application is controlled by external clients
                       via the API.
   --norestore         Disables restart and file recovery after a system crash.
   --safe-mode         Starts in a safe mode, i.e. starts temporarily with a
                       fresh user profile and helps to restore a broken
                       configuration.
   --accept={connect-string}  Specifies a UNO connect-string to create a UNO
                       acceptor through which other programs can connect to
                       access the API. Note that API access allows execution
                       of arbitrary commands.
                       The syntax of the {connect-string} is:
                         connection-type,params;protocol-name,params
                       e.g.  pipe,name={some name};urp
                         or  socket,host=localhost,port=54321;urp
   --unaccept={connect-string}  Closes an acceptor that was created with
                       --accept. Use --unaccept=all to close all acceptors.
   --language={lang}   Uses specified language, if language is not selected
                       yet for UI. The lang is a tag of the language in IETF
                       language tag.

Developer arguments:
   --terminate_after_init
                       Exit after initialization complete (no documents loaded)
   --eventtesting      Exit after loading documents.

New document creation arguments:
The arguments create an empty document of specified kind. Only one of them may
be used in one command line. If filenames are specified after an argument,
then it tries to open those files in the specified component.
   --writer            Creates an empty Writer document.
   --calc              Creates an empty Calc document.
   --draw              Creates an empty Draw document.
   --impress           Creates an empty Impress document.
   --base              Creates a new database.
   --global            Creates an empty Writer master (global) document.
   --math              Creates an empty Math document (formula).
   --web               Creates an empty HTML document.

File open arguments:
The arguments define how following filenames are treated. New treatment begins
after the argument and ends at the next argument. The default treatment is to
open documents for editing, and create new documents from document templates.
   -n                  Treats following files as templates for creation of new
                       documents.
   -o                  Opens following files for editing, regardless whether
                       they are templates or not.
   --pt {Printername}  Prints following files to the printer {Printername},
                       after which those files are closed. The splash screen
                       does not appear. If used multiple times, only last
                       {Printername} is effective for all documents of all
                       --pt runs. Also, --printer-name argument of
                       --print-to-file switch interferes with {Printername}.
   -p                  Prints following files to the default printer, after
                       which those files are closed. The splash screen does
                       not appear. If the file name contains spaces, then it
                       must be enclosed in quotation marks.
   --view              Opens following files in viewer mode (read-only).
   --show              Opens and starts the following presentation documents
                       of each immediately. Files are closed after the showing.
                       Files other than Impress documents are opened in
                       default mode , regardless of previous mode.
   --convert-to OutputFileExtension[:OutputFilterName] \
     [--outdir output_dir] [--convert-images-to]
                       Batch convert files (implies --headless). If --outdir
                       isn't specified, then current working directory is used
                       as output_dir. If --convert-images-to is given, its
                       parameter is taken as the target filter format for *all*
                       images written to the output format. If --convert-to is
                       used more than once, the last value of
                       OutputFileExtension[:OutputFilterName] is effective. If
                       --outdir is used more than once, only its last value is
                       effective. For example:
                   --convert-to pdf *.odt
                   --convert-to epub *.doc
                   --convert-to pdf:writer_pdf_Export --outdir /home/user *.doc
                   --convert-to "html:XHTML Writer File:UTF8" \
                                --convert-images-to "jpg" *.doc
                   --convert-to "txt:Text (encoded):UTF8" *.doc
   --print-to-file [--printer-name printer_name] [--outdir output_dir]
                       Batch print files to file. If --outdir is not specified,
                       then current working directory is used as output_dir.
                       If --printer-name or --outdir used multiple times, only
                       last value of each is effective. Also, {Printername} of
                       --pt switch interferes with --printer-name.
   --cat               Dump text content of the following files to console
                       (implies --headless). Cannot be used with --convert-to.
   --script-cat        Dump text content of any scripts embedded in the files
                       to console (implies --headless). Cannot be used with
                       --convert-to.
   -env:<VAR>[=<VALUE>] Set a bootstrap variable. For example: to set
                       a non-default user profile path:
                       -env:UserInstallation=file:///tmp/test

Ignored switches:
   -psn                Ignored (MacOS X only).
   -Embedding          Ignored (COM+ related; Windows only).
   --nofirststartwizard Does nothing, accepted only for backward compatibility.
   --protector {arg1} {arg2}
                       Used only in unit tests and should have two arguments.

Section6、别名配置

也许聪明的你已经发现了,LibreOffice的命令行工具在 linux 下是 libreoffice7.0 这种有版本号的,而在 MacOS 中一般是手动添加命令映射 soffice,您可以在我的另一篇博文 《MacOS环境在终端使用Libreoffice的soffice命令》中找到相关说明。一个是 libreoffice<version> 一个是 soffice ,非常不够统一,为了方便起见我们需要在linux环境中配置一下别名。编辑 /etc/profile 文件在最后添加一行代码如下所示:

1
alias soffice="libreoffice7.0"

保存之前执行一个 source 命令

1
bash-4.4# source /etc/profile

现在我们就可以在多个不同的系统平台使用相同的命令了,如

1
bash-4.4# soffice -h

Section7、使用

接下来我们尝试将PDF转换为Word文档。

1
2
3
bash-4.4# soffice --invisible --convert-to docx:"MS Word 2007 XML" libreoffice.pdf
javaldx: Could not find a Java Runtime Environment!
Warning: failed to read path from javaldx

正如你所见它说打不到JAVA运行时环境,好嘛,又来了,我们干掉你,执行如下YUM命令

1
bash-4.4# yum install -y java

再次尝试转换,这次成功啦~

1
2
bash-4.4# soffice --invisible --infilter="writer_pdf_import" --convert-to docx:"MS Word 2007 XML" libreoffice.pdf
convert /root/libreoffice.pdf -> /root/libreoffice.docx using filter : MS Word 2007 XML

下面是后的Word文档第一页截图

LibreOfficeConvertPDFToWord

参考官方文档

comments powered by Disqus