ubuntu系统只下载某个软件包而不安装它的命令

前言:

以下内容翻译自:Download Packages With Dependencies Locally In Ubuntu - OSTechNix

并添加了一些评价。

推荐方法3

步骤1:创建空文件夹,并进入

步骤2: 在命令行中输入以下命令(把红色字体的位置,换成自己需要的deb-name即可,可以连续放置多个,中间用空格隔离):

for i in $(apt-cache depends deb_name | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done
步骤3:安装离线软件包
$ sudo dpkg -i deb_name.deb # deb_name是自己指定的那个deb,最好是全称

示例:下载 xfce4 xrdp vnc4server 三个软件及其依赖包

$ for i in $(apt-cache depends xfce4 xrdp vnc4server | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done

方法1:下载deb包及其依赖

相比下面的其他方法,这是最简单且最直接的方法。

$ sudo apt-get install --download-only <package_name>

示例,当下载 Vim 及其依赖且不安装的时候,使用下面的命令: 

$ sudo apt-get install --download-only vim

所有的文件被下载并被保存在  /var/cache/apt/archives 文件夹。

安装下载得到的deb文件:

$ sudo dpkg -i *

优点:简单方便

 缺点:

        1)所有的文件被下载并被保存在  /var/cache/apt/archives 文件夹。会与其他文件混杂在一起。

        2)当下载deb包的系统中已经安装了你想要下载的deb包,系统将无法执行下载操作。会出现以下情况:

$ sudo apt-get install --download-only vim
Reading package lists... Done
Building dependency tree 
Reading state information... Done
vim is already the newest version (2:8.0.1453-1ubuntu1.3).
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

此时,需要使用"apt-rdepends"命令去下载deb包。

方式2:递归地下载带有依赖项的包

首先,需要在系统里安装deb软件:apt-rdepends

$ sudo apt install apt-rdepends

然后,用以下命令下载deb包:

$ apt-get download $(apt-rdepends deb包名| grep -v "^ " | sed 's/debconf-2.0/debconf/g')

 比如,下载vim及其依赖包:

$ apt-get download $(apt-rdepends vim | grep -v "^ " | sed 's/debconf-2.0/debconf/g')

安装时,使用以下命令安装即可 

$ sudo dpkg -i *

默认安装位置:  /var/cache/apt/archives 文件夹。

优点:方便,可以解决方法1的问题。

缺点:默认把所有的deb文件都下载到 /var/cache/apt/archives 文件夹中,导致多个deb文件的安装包的依赖包混杂在一起,不便于拷贝到其他机器上安装。

下面的方法可以解决这个问题

方法3: 下载deb包及其依赖到指定文件夹

3.1 查看一个deb文件的依赖:

$ sudo apt-cache depends deb_name

比如,查看python软件的依赖:

$ sudo apt-cache depends python

输出结果如下:

python
PreDepends: python-minimal
Depends: python2.7
Depends: libpython-stdlib
Conflicts: <python-central>
Breaks: update-manager-core
Suggests: python-doc
Suggests: python-tk
Replaces: python-dev

下面,下载python软件及其依赖:

3.2 下载deb文件及其依赖到指定文件夹

首先,创建一个文件夹,用于存储即将下载的包

$ mkdir python_pkgs

进入创建的文件夹:

$ cd python_pkgs

运行以下命令

$ for i in $(apt-cache depends deb包名| grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done

比如:

$ for i in $(apt-cache depends python | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done

以上命令将下载python安装包及其所需要的依赖包,并保存在当前的工作文件夹中。同时,这个命令将会把错误信息保存到error.txt文件中。 

此时,可以把该文件夹拷贝到其他机器上进行安装了。

优点:条理性好,所下载的包可迁移性好

缺点:命令比较长(但是只需要复制粘贴,修改一个位置即可,也不麻烦)

扩展:

1. 为特定的体系结构在本地下载带有依赖项的包

You might notice that the above command has downloaded the 64 bit packages. It is because I am downloading them from the 64-bit Ubuntu system. What if you want to download packages for 32-bit arch systems? It's also possible!

First, enable the architecture you want in your Ubuntu system using command:

$ sudo dpkg --add-architecture i386

If you don't add the architecture, you will get the following error message when try to download the packages.

E: No packages found

After enabling the Architecture of your choice, run the following command to download specific architecture related packages.

$ for i in $(apt-cache depends python:i386 | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do sudo apt-get download $i 2>>errors.txt; done

As you see in the above output, I have added the architecture 'i386' with 'apt-cache' command.

Sample output:

Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main i386 python-minimal i386 2.7.11-1 [28.2 kB]
Fetched 28.2 kB in 1s (25.8 kB/s) 
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main i386 python2.7 i386 2.7.11-7ubuntu1 [220 kB]
Fetched 220 kB in 1s (116 kB/s) 
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main i386 libpython-stdlib i386 2.7.11-1 [7,664 B]
Fetched 7,664 B in 0s (13.3 kB/s) 
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main i386 python-tk i386 2.7.11-2 [28.0 kB]
Fetched 28.0 kB in 1s (24.8 kB/s)

Download packages with dependencies locally for a specific architecture

Download packages with dependencies locally for a specific architecture

Let us check the downloaded packages.

$ ls

Sample output:

errors.txt
libpython-stdlib_2.7.11-1_i386.deb
python2.7_2.7.11-7ubuntu1_i386.deb
python-minimal_2.7.11-1_i386.deb
python-tk_2.7.11-2_i386.deb

See? The above command downloaded the 32 bit packages only.

You know now how to download packages with dependencies in Ubuntu systems. These methods are same for all DEB-based systems.






附录:以下方法来自其他博客,与以上内容有重复,可以不用看

附录1:

sudo apt download ftpd

特点:下载单个deb文件。

存储位置:当前shell所在位置。

附录2: 

sudo apt install --download-only ftpd

或 

sudo apt-get --download-only install freesweep

 特点:下载软件及其依赖包,

默认的下载位置是:/var/chahe/apt/archive

附录2:扩展

下面的指令可以查找一个deb包的依赖包

apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances --no-pre-depends xxx软件包 | grep -v i386 | grep "^\w"

下面的指令可以只下载软件包而不安装

sudo apt-get install --reinstall -d -y xxx软件包

附录3:下载deb包及其依赖 

apt-get download $(apt-rdepends (deb包名,可以有多个) | grep -v "^ " | sed 's/debconf-2.0/debconf/g')

比如下载ftpd的deb包及其依赖:

apt-get download $(apt-rdepends ftpd | grep -v "^ " | sed 's/debconf-2.0/debconf/g')

更多:

解压deb文件

dpkg -x freesweep_amd64.deb free

自定义编译deb文件:

dpkg-deb --build /mnt/free

安装deb文件:

dpkg -i free.deb

参考:

[1] ubuntu系统只下载某个软件包而不安装它的命令_apt只下载不安装-CSDN博客

[2] https://blog.csdn.net/u012206617/article/details/105094522 

[3] 下载deb及其依赖软件包,离线安装deb软件包_deb软件包下载-CSDN博客 

[4] Download Packages With Dependencies Locally In Ubuntu - OSTechNix 

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值