是否可以避免使用 sudo 执行 make 和 make install?

是否可以避免使用 sudo 执行 make 和 make install?

只要有可能,我就会尝试使用通过官方 Ubuntu APT 提供的应用程序、库和插件。但是,有时我会尝试编译一些东西,比如resynthesizerGIMP 插件。在许多情况下,编译需要我执行sudo makesudo make install。如果没有这些,脚本就会失败,因为它们会尝试将文件复制到 root 有权限的文件夹中。

由于我不是该程序的作者,我真的很害怕这样做(以超级用户身份执行此类脚本)。我担心这会破坏系统。是否可以在不使用的情况下安全地编译程序sudo

答案1

总是有可能编译软件“本地”位于您自己的主目录下 - 本地安装和运行的难易程度取决于软件的开发人员。

对于使用熟悉automake方法的开源软件

./configure
make 
make install

configure脚本通常应该提供一个--prefix设置安装路径根目录的选项 - 例如

./configure --prefix=$HOME

将导致生成的二进制文件安装到调用用户的~/bin,将库安装到~/lib,将配置文件安装到~/etc等等。如果目录尚不存在,则会自动创建。

在特定情况下gimp 再合成器插件然而,该make install步骤显然仍尝试安装几个文件到$(GIMP_LIBDIR)/plug-ins,其中GIMP_LIBDIR = /usr/lib/gimp/2.0是硬编码的,而不是从--prefix值中得出的。

这可能是软件维护人员的疏忽,也可能是为了与 GIMP 本身兼容。但是,您可以通过修改配方来克服它,如下所示:

./configure --prefix=$HOME
make
make GIMP_LIBDIR=$HOME/lib/gimp/2.0/ install

这应该导致以下插件目录结构:

$ find ~/lib -newermt yesterday
/home/username/lib
/home/username/lib/gimp
/home/username/lib/gimp/2.0
/home/username/lib/gimp/2.0/plug-ins
/home/username/lib/gimp/2.0/plug-ins/plugin-map-style.py
/home/username/lib/gimp/2.0/plug-ins/plugin-heal-transparency.py
/home/username/lib/gimp/2.0/plug-ins/plugin-resynth-enlarge.py
/home/username/lib/gimp/2.0/plug-ins/plugin-render-texture.py
/home/username/lib/gimp/2.0/plug-ins/resynthesizer
/home/username/lib/gimp/2.0/plug-ins/resynthesizer_gui
/home/username/lib/gimp/2.0/plug-ins/plugin-resynth-sharpen.py
/home/username/lib/gimp/2.0/plug-ins/plugin-uncrop.py
/home/username/lib/gimp/2.0/plug-ins/plugin-heal-selection.py
/home/username/lib/gimp/2.0/plug-ins/plugin-resynth-fill-pattern.py

相关内容