- QGIS软件及其应用教程
- 董昱 胡云锋 王娜编著
- 925字
- 2024-11-01 00:03:22
2.1.2 在Linux系统中的安装方法
在Linux系统中安装QGIS包括两种基本方式:通过编译源代码安装和通过软件包管理器(如yum、apt源等)安装。QGIS的编译方式较复杂,需要一定的软件编程基础,否则很容易出现编译错误等情况。
本节介绍通过Ubuntu、Debian和CentOS的软件包管理器安装QGIS的方法。
1. 在Ubuntu/Debian系统安装QGIS
下面以Ubuntu 18.04 LTS为例,介绍通过apt源安装QGIS的方法,具体操作如下。
(1)增加QGIS官方的apt源。Ubuntu自带的apt源的QGIS更新速度较慢,如果希望使用最新版本的QGIS,需要在系统中增加QGIS官方的apt源。
在Ubuntu系统中增加apt源需要在/etc/apt/sources.list文件中添加以下代码:

将“*repository*”修改为apt仓库地址(见表2-1),将“*codename*”修改为Ubuntu/Debian版本代号,需要根据操作系统版本选择合适的代号(见表2-2)。
表2-1 QGIS官方常用的apt源

表2-2 QGIS apt源支持的Ubuntu/Debian发行版及其版本代号

【小提示】由于QGIS的更新速度较快,读者可以在以下网站查询最新的apt源及其支持信息:https://qgis.org/en/site/forusers/alldownloads.html#debian-ubuntu。
例如,在Ubuntu 18.04 LTS中,安装QGIS最新版的代码如下:

在Ubuntu 18.04 LTS中,安装QGIS LTR的代码如下:

按需求将这些代码加入/etc/apt/sources.list文件中。本节以安装QGIS LTR为例进行介绍,如图2-7所示。

图2-7 在Ubuntu/Debian系统下增加QGIS官方的apt源
保存上述sources.list文件,并在控制台下运行下面的命令更新apt源。

注意,如果在更新apt源时出现了GPG错误(见图2-8),需要增加QGIS的GPG公钥,代码如下:


图2-8 在Ubuntu/Debian系统下安装QGIS时出现GPG错误提示
(2)在控制台运行以下命令安装QGIS:

或者运行以下命令,同时安装QGIS与GRASS的QGIS插件:

安装完成后即可运行QGIS,如图2-9所示。

图2-9 Ubuntu/Debian系统下的QGIS主页面
2. 在CentOS系统中安装QGIS
下面以epel仓库为例,在CentOS 7.7下安装QGIS LTR,具体操作如下。
(1)增加epel仓库。为了使用较快的epel仓库,可以使用第三方提供的开源镜像站。例如,本例使用阿里云的epel仓库镜像。在控制台输入以下代码即可增加epel仓库(见图2-10):


图2-10 在CentOS系统中增加epel仓库
代码中加粗的部分需要与CentOS版本一致,读者可以参阅阿里云镜像站获得相关信息。
(2)通过以下代码更新yum源:

(3)在控制台运行下面的命令安装QGIS:

或者运行以下命令,同时安装QGIS、QGIS的Python工具包与GRASS的QGIS插件:

安装完成后即可打开QGIS LTR(见图2-11)。

图2-11 CentOS系统下的QGIS主页面
【小提示】如果用户对操作系统的要求不高,通过下载运行或安装OSGeoLive也可以在Linux环境(Lubuntu)下使用QGIS。OSGeoLive 13.0版本已经集成了QGIS 3.4 LTR和众多开源GIS软件和工具。
OSGeoLive的官方网站:http://live.osgeo.org/en/index.html。
OSGeoLive的中文网站:https://www.osgeo.cn/osgeo-live/。