当前位置:   article > 正文

linux更新一个软件包,使用apt-get在Ubuntu/Debian系统中升级单个软件包的方法

linux实现升级其中一个应用

本文介绍在Ubuntu/Debian系统中使用apt-get升级单个软件包,升级软件包的最常用方法是运行命令sudo apt-get upgrade,但是这样做的结果是所有已安装的软件包都将升级到配置的Ubuntu存储库中可用的最新版本。

ac915d6137e43a986354d2f24df1d0bf.png

使用apt-get在Ubuntu/Debian中升级单个软件包

1、要在任何基于Ubuntu/Debian的系统中使用apt-get(Debian和Ubuntu最实用的apt-get命令详解)升级单个软件包,请使用以下syntax:

sudo apt-get install --only-upgrade packagename

这适用于所有Ubuntu、Debian和Linux Mint系统,将packagename替换为要升级的程序包的名称即可。

2、请参阅下面的示例以升级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 2018.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_2018.09.18.1~18.04.0_all.deb …

Unpacking ubuntu-keyring (2018.09.18.1~18.04.0) over (2018.02.28) …

Setting up ubuntu-keyring (2018.09.18.1~18.04.0) …

在Ubuntu/Debian/Linux Mint中升级多个软件包

1、要升级多个包,请用空格分隔它们:

sudo apt-get install --only-upgrade thunderbird cinnamon cinnamon-common

2、如果要升级所有已安装的软件包,请使用以下命令:

sudo apt-get upgrade

使用脚本在Ubuntu中升级单个程序包/多个程序包

1、我们可以创建一个简单的脚本,每当你想在Ubuntu或Debian系统中使用apt-get升级单个包时,我们就会将包名称作为参数传递。使用以下内容在/usr/local/bin/myupgrade中创建脚本:

#!/bin/bash

pakage_names="$@"

[[ -z $pakage_names ]] && { echo "Usage: $(basename $0) 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

2、给脚本一个执行位:

sudo chmod +x /usr/local/bin/myupgrade

3、必须将参数传递给脚本才能升级包:

$ myupgrade

Usage: myupgrade package1 package 2 package..

4、要升级单个包,请在末尾传递单个参数

$ 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) …

5、对于多个包,请提供以空格分隔的名称:

$ myupgrade nplan openssl perl

6、如果尚未安装软件包,脚本将询问你是否要安装它,按“Y”或“y”确认:

$ 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.

至此,操作完成。

相关主题

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/577526
推荐阅读
相关标签
  

闽ICP备14008679号