如何在Synaptic中链接已从源码安装的GRASS GIS依赖项以安装QGIS开发版


阅读 8 次

问题背景

最近在尝试从SVN源码安装Quantum GIS(QGIS)的开发版本时遇到了依赖问题。根据QGIS官方Wiki的说明,我已经将qgis仓库添加到sources.list文件中,可以在Synaptic包管理器中看到qgis1.8.0svn版本。但安装时发现它依赖GRASS GIS,而Ubuntu官方仓库和GIS Unstable PPA中提供的GRASS版本(6.4)都不是我需要的开发版本(6.5)。

现有环境

我已经通过svn checkout方式在/usr/local/目录下安装了GRASS GIS 6.5的开发版本。现在需要让Synaptic识别这个已安装的版本,而不是尝试从仓库安装旧版本。

解决方案

在Debian/Ubuntu系统中,可以通过创建虚拟包(fake package)来解决这个问题。具体步骤如下:

# 1. 创建控制文件
mkdir -p ~/grass-fake/DEBIAN
cat > ~/grass-fake/DEBIAN/control << EOF
Package: grass
Version: 6.5.0-1
Section: science
Priority: optional
Architecture: all
Depends: libc6 (>= 2.7)
Description: Fake package to satisfy QGIS dependency
 This is a fake package to satisfy QGIS's dependency on GRASS GIS 6.5.
 It assumes GRASS is already installed from source in /usr/local/
Maintainer: Your Name <your.email@example.com>
EOF

# 2. 构建deb包
dpkg-deb --build ~/grass-fake

# 3. 安装虚拟包
sudo dpkg -i ~/grass-fake.deb

# 4. 阻止apt-get升级此包
sudo apt-mark hold grass

替代方案:使用equivs

如果不想手动创建deb包,可以使用equivs工具:

sudo apt-get install equivs
equivs-control grass-control

然后编辑生成的grass-control文件,内容如下:

Section: science
Priority: optional
Standards-Version: 3.9.2

Package: grass
Version: 6.5.0-1
Maintainer: Your Name <your.email@example.com>
Architecture: all
Description: Fake GRASS package
Depends: ${misc:Depends}

构建并安装包:

equivs-build grass-control
sudo dpkg -i grass_6.5.0-1_all.deb

验证安装

安装完成后,可以运行以下命令验证:

dpkg -l | grep grass

应该能看到类似这样的输出:

ii  grass  6.5.0-1  all  Fake package to satisfy QGIS dependency

注意事项

1. 这种方法只是告诉包管理系统依赖已满足,不会实际安装任何文件
2. 确保你的源码安装的GRASS确实在系统PATH中
3. 如果GRASS的库文件不在标准位置,可能需要设置LD_LIBRARY_PATH

对于库文件路径问题,可以创建conf文件:

sudo tee /etc/ld.so.conf.d/grass.conf << EOF
/usr/local/lib
EOF
sudo ldconfig