如何使用 apt-get 安装软件包列表?

如何使用 apt-get 安装软件包列表?

我刚刚安装了 Lubuntu,想从给定的列表中安装软件包,而不必键入sudo apt-get install package_name。 可以吗?

我并不是在谈论安装后脚本,那是完全不同的东西。

答案1

如果你有一个文件(比如说pkglist),其中包含要安装的软件包列表,例如:

pkg1
pkg2
pkg3

或者

pkg1 pkg2 pkg3

apt然后您可以使用以下任一命令安装这些包:

  1. sudo apt-get install $(cat pkglist)

  2. xargs sudo apt-get install < pkglist

  3. for i in $(cat pkglist); do sudo apt-get install $i; done

建议使用第三个,因为即使pkgs存储库中找不到某些包,它也能正常工作,而前两个将无法安装可用的包,如此评论

欲了解更多信息,请apt-get install访问man apt-get安装部分。

答案2

是的,只需将所有包列在一行中,并用空格分隔即可。例如

sudo apt-get install package_name1 package_name2 package_name3 package_name4

答案3

将所有包名放入一个文件中(每行一个包名)。然后运行以下命令自动安装给定的包。

while read -r line; do sudo apt-get -y install "$line"; done < /path/to/the/packages/file

例子:

$ cat file
vlc
firefox
$ while read -r line; do sudo apt-get install "$line"; done < file
[sudo] password for avinash: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
vlc is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 499 not upgraded.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  ttf-lyx
The following packages will be upgraded:
  firefox
1 upgraded, 0 newly installed, 0 to remove and 498 not upgraded.
Need to get 35.8 MB of archives.
After this operation, 24.3 MB of additional disk space will be used.
Get:1 http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-updates/main firefox amd64 33.0+build2-0ubuntu0.14.04.1 [35.8 MB]
0% [1 firefox 67.0 kB/35.8 MB 0%]                           10.4 kB/s 57min 16s^

相关内容