如何在 Debian/Ubuntu/Kali 上重新打包 已安装的 软件

Posted ~晨曦静竹~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在 Debian/Ubuntu/Kali 上重新打包 已安装的 软件相关的知识,希望对你有一定的参考价值。

  How To Repack Installed Software on Debian/Ubuntu

  It can happen that a particular version of a specific tweaked package no longer available elsewhere or you want the exact “clone” of the running software. If you have installed some Debian package on your server and want to install the same package on another server either to avoid downloading them again or “clone” with the settings then there are some tools which can help you. If the second machine lacks an internet connection then you’ll need to install the dependencies as well.

  划重点:
	1. 如何将 Debian系 Linux系统或服务器上已安装的软件重新打包,制作 deb 安装包;
	2. 能否实现软件环境的克隆,以避免因缺失依赖而项导致的无法安装;
	3. 保持软件原来的设置状态迁徙,减少后续重新设置时的工作量。

  面对如上困境,博主推荐使用 dpkg-repack 和 apt-clone工具 ~~

   一、 Dpkg-Repack

  dpkg-repack 是一款能对已安装软件进行deb打包的软件。

  Dpkg-Repack 软件的 Ubuntu 使用手册: https://manpages.ubuntu.com/manpages/kinetic/en/man1/dpkg-repack.1.html

  安装方法:
	sudo apt install dpkg-repack -y




  安装成功后,以我 Kali Linux 操作系统中的 百度输入法为例:

   打包百度输入法 Linux版:
	 dpkg-repack fcitx-baidupinyin


  可以看到,在当前文件夹下,生成了名为 fcitx-baidupinyin_1.0.1.0_amd64.deb 的包,对,这是我使用了一年的老旧百度输入法,版本为 1.01,由此,证实 dpkg-repack 工具的确可将已安装的软件重新打包回 deb包。

  如果由于任何权限问题而无法重建 deb 文件,请从fakeroot环境中运行命令:

	fakeroot -u dpkg-repack <package-name>

  我们可以在运行原始软件的主服务器上打印依赖项:

	apt-cache depends Package_name |awk 'print $2'

  也可尝试创建脚本来自动安装依赖项:

package=package
dpkg-repack $(apt-cache depends --false-suggests $package |awk 'print $2') $package

  注意,dpkg-repack 是无法复制你对软件的自定义设置的。它仅能对某台Debian系的系统或服务器上的软件进行deb的打包重建。

  或许有小伙伴想,要是能保持软件设置状态和依赖项移植过去就好了,这样就能顺利的安装,并节省重新设置的时间啦!!

  不着急,热心帅气的博主已为你想好了方法~


   一、Apt-Clone

   apt-clone 是一款非常使用的程序,能够 帮助 dekg-repack 重新构建deb的同时保留被打包软件的设置项和依赖环境。

  Apt-Clone 软件的 Ubuntu 使用手册: http://manpages.ubuntu.com/manpages/bionic/man8/apt-clone.8.html

  Apt-Clone的 Debian 官网下载:https://packages.debian.org/stretch/apt-clone


  当然,该软件同样可通过CLI进行安装:

	apt-get install apt-clone -y

   可以通过 apt 先查阅软件依赖项:

	 C:\\root> apt-cache depends fcitx-baidupinyin | awk 'print $2'
	
	libc6
	fcitx-bin
	fcitx-data
	fcitx-modules
	libglib2.0-0
	libqt5core5a
	qml-module-qtquick-controls
	fcitx
	fcitx	



   指定构建被迁徙软件的 apt-clone.tar.gz 环境包:

	 apt-clone clone fcitx-baidupinyin --with-dpkg-repack


  构建完成:
  最后将构建好的 apt-clone.tar.gz 移动到目标服务器中恢复构建即可:

	apt-clone restore fcitx-baidupinyin.apt-clone.tar.gz

  You can manually install the same packages from one server to another with the below commands :

	dpkg -l | grep ^ii | awk 'print $2' > installed
	# another server
	sudo apt-get install $(cat installed)

  Usually, the settings are saved in the /etc/ directory. There are tools such as etckeeper which can be used with git to restore the settings :
   http://etckeeper.branchable.com/


  注:
  Ubuntu的文档手册和 etckeeper 或许需要科学上网才可访问,但仍建议使用前先阅读。
  另外, 该项过程将 耗费读者 较多的磁盘空间 和操作 时间,请耐心细致的去工作,并酌情处理~~

以上是关于如何在 Debian/Ubuntu/Kali 上重新打包 已安装的 软件的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Debian/Ubuntu/Kali 上重新打包 已安装的 软件

Debian/Ubuntu/Kali 如何安装 Spotify 音乐白嫖神器

Debian/Ubuntu/Kali 如何安装 Spotify 音乐白嫖神器

Debian/Ubuntu/Kali 如何安装 Spotify 音乐白嫖神器

如何在 GitHub 网站上重命名分支?

如何在Angular中的同一模块上重定向