Learn how to – Upgrade Single Package on Ubuntu / Debian using apt-get.
How can I upgrade a single package on Ubuntu/Debian/Linux Mint using apt-get command line tool?. The most common way of upgrading packages on Ubuntu/Debian is by running the command sudo apt-get upgrade
. The problem with this is that all installed packages will be upgraded to the latest versions available in configured Ubuntu repositories.
![Upgrade Single Package on Ubuntu / Debian using apt-get 1](https://ownyourlife.com.ng/wp-content/uploads/2023/06/291_ngcb23.webp)
What if you want to upgrade a single package with apt-get
on Ubuntu or Debian machine?. This is relevant if you are afraid of having broken packages from upgrading everything.
Upgrade a single package on Ubuntu / Debian using apt-get
To upgrade a single package with apt-get on any Ubuntu / Debian based system, use the syntax:
sudo apt-get install --only-upgrade packagename
This will work for all Ubuntu, Debian and Linux Mint systems. Replace packagename
with the name of the package you want to upgrade.
See example below to 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) …
Upgrade multiple packages on Ubuntu / Debian / Linux Mint
To upgrade multiple packages, separate them by a space.
sudo apt-get install --only-upgrade thunderbird cinnamon cinnamon-common
If you want to upgrade all installed packages, use the command:
sudo apt-get upgrade
Upgrade a single package / multiple packages on Ubuntu with a script
We can create a simple script that we’ll be passing package name(s) as arguments everytime you want to upgrade a single package with apt-get on Ubuntu or Debian system.
Create a script in /usr/local/bin/myupgrade
with below content.
#!/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
Give the script an execution bit.
sudo chmod +x /usr/local/bin/myupgrade
You must pass arguments to the script to to upgrade package.
$ myupgrade
Usage: myupgrade package1 package 2 package..
To upgrade single package, pass single argument at the end
$ 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) …
For multiple package, provide names separated by space.
$ myupgrade nplan openssl perl
If the package is not already installed, the script will ask you if you want to install it. Confirm by pressing “Y” or “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.
.....
That’s the end of our guide on how to upgrade a single package with apt-get on Ubuntu/Debian. I hope this was helpful and thanks for visiting.
Also check:
Add Debian 10 Buster official repositories to sources.list
How to Install add-apt-repository on Debian / Ubuntu
Creating Ubuntu Mirrors using apt-mirror
Leave a Reply
You must be logged in to post a comment.