使用APT-GET升级Ubuntu/Debian上的单个安装包
时间:2020-02-23 14:32:53 来源:igfitidea点击:
如何使用APT-GET命令行工具升级Ubuntu/debian/linux mint上的单个包装?
通过运行命令,升级Ubuntu/Debian上的包的最常用方式 sudo apt-get upgrade
。
此问题的问题是所有已安装的包都将升级到已配置的Ubuntu存储库中可用的最新版本。
如果要升级单个包装,该怎么办 apt-get
在Ubuntu或者Debian机器上?
如果我们害怕升级所有内容,则这是相关的。
使用apt-get升级Ubuntu/Debian上的单个安装包
要升级单个包,请在任何Ubuntu/debian基于Ubuntu/debian系统上升级单个包,使用语法:
sudo apt-get install --only-upgrade packagename
这将适用于所有Ubuntu,Debian和Linux Mint系统。
代替 packagename
使用我们要升级的包的名称。
查看以下示例以升级 ubuntu-keyring
。
$sudo apt-get install --only-upgrade ubuntu-keyring Reading package lists… Done Building dependency tree Reading state information… Done The following packages will be upgraded: ubuntu-keyring 1 upgraded, 0 newly installed, 0 to remove and 190 not upgraded. Need to get 22.4 kB of archives. After this operation, 4,096 B of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 ubuntu-keyring all 2016.09.18.1~18.04.0 [22.4 kB] Fetched 22.4 kB in 1s (34.5 kB/s) (Reading database … 261497 files and directories currently installed.) Preparing to unpack …/ubuntu-keyring_2016.09.18.1~18.04.0_all.deb … Unpacking ubuntu-keyring (2016.09.18.1~18.04.0) over (2016.02.28) … Setting up ubuntu-keyring (2016.09.18.1~18.04.0) …
升级Ubuntu/Debian/Linux Mint上的多个包
要升级多个包,请将它们分开。
sudo apt-get install --only-upgrade thunderbird cinnamon cinnamon-common
如果要升级所有已安装的包,请使用命令:
sudo apt-get upgrade
用脚本升级Ubuntu上的单个包/多个包
我们可以创建一个简单的脚本,我们将通过包将包名称传递为每次要升级单个包,以Apt-get on Ubuntu或者Debian系统升级。
创建一个脚本 /usr/local/bin/myupgrade
内容以下。
#!/bin/bash pakage_names="Hyman@theitroad" [[ -z $pakage_names ]] && { echo "Usage: $(basenamesudo chmod +x /usr/local/bin/myupgrade) package1 package 2 package.."; exit 1; } # Check if package is already installed for package in ${pakage_names[@]}; do if dpkg -s "$package" 2>/dev/null | grep -q Status.*installed; then echo "Attempting to upgrade $package" sudo apt-get --only-upgrade -y install $package else echo "Package $package is not installed, install it (y/n): " read selection if [[ $selection == "y" ]] || [[ $selection == "Y" ]]; then sudo apt-get -y install $package else echo "Okay!, next time" fi fi done
给脚本执行位。
$myupgrade Usage: myupgrade package1 package 2 package..
我们必须将参数传递给脚本以升级包。
$myupgrade util-linux Attempting to upgrade util-linux [sudo] password for jmutai: Reading package lists… Done Building dependency tree Reading state information… Done Suggested packages: util-linux-locales The following packages will be upgraded: util-linux 1 upgraded, 0 newly installed, 0 to remove and 182 not upgraded. Need to get 902 kB of archives. After this operation, 0 B of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 util-linux amd64 2.31.1-0.4ubuntu3.3 [902 kB] Fetched 902 kB in 2s (518 kB/s) (Reading database … 261497 files and directories currently installed.) Preparing to unpack …/util-linux_2.31.1-0.4ubuntu3.3_amd64.deb … Unpacking util-linux (2.31.1-0.4ubuntu3.3) over (2.31.1-0.4ubuntu3.2) … Setting up util-linux (2.31.1-0.4ubuntu3.3) … Processing triggers for mime-support (3.60ubuntu1) … Processing triggers for ureadahead (0.100.0-20) … Processing triggers for systemd (237-3ubuntu10.9) … Processing triggers for man-db (2.8.3-2ubuntu0.1) …
要升级单个包,请在最后传递单个参数
$myupgrade nplan openssl perl
对于多个包,提供由空间分隔的名称。
$myupgrade elinks Package elinks is not installed, install it (y/n) y Reading package lists… Done Building dependency tree Reading state information… Done The following additional packages will be installed: elinks-data libfsplib0 liblua5.1-0 libtre5 Suggested packages: elinks-doc tre-agrep The following NEW packages will be installed: elinks elinks-data libfsplib0 liblua5.1-0 libtre5 0 upgraded, 5 newly installed, 0 to remove and 169 not upgraded. Need to get 1,062 kB of archives. .....
如果尚未安装包,则脚本将询问我们是否要安装它。
按"Y"或者"Y"确认。