How to upgrade a specific package using apt-get?

You just need to do apt-get install --only-upgrade <packagename>. This will upgrade only that single package, and only if it is installed.

If you wish to install the package if it doesn’t exist, or upgrade it if it does, you may leave out --only-upgrade.

How to upgrade a specific package using apt-get?

In order to update a single package using the CLI:

sudo apt-get install --only-upgrade <packagename>

e.g., sudo apt-get install --only-upgrade ack

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Skipping **ack**, it is not installed and only upgrades are requested.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Answer #3:

There are two possible ways I can think of:

1). sudo apt-get install nameofpackage
This will upgrade the package even if is already installed:

~$ sudo apt-get install emesene
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  emesene
1 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
Need to get 1,486 kB of archives.
After this operation, 696 kB disk space will be freed.
Get:1 http://il.archive.ubuntu.com/ubuntu/ natty-updates/universe emesene all 2.11.4+dfsg-0ubuntu1 [1,486 kB]

2). UsingSynaptic Package ManagerRight click→Mark for upgrade:

Note: Sometimes it may asks for additional packages or dependencies, it is normal.

Answer #4:

In my experience on Ubuntu 12.04 LTS, using the command below will not upgrade the package if using a separate PPA –

sudo apt-get --only-upgrade install <packagename>

Similarily, I did not want to run the upgrade command, which would upgrade all packages on my server –

sudo apt-get dist-upgrade

For example, I have PHP 5.3 installed and have added the ondrej PPA to my apt.sources using –

sudo add-apt-repository ppa:ondrej/php5

If I run

sudo apt-get install php5

it will just reinstall PHP 5.3.

I have to, first, determine the version number to upgrade to, using

sudo apt-cache policy php5

This will list all available version numbers. You should find the version number you want to upgrade to, and then copy the whole string that references it. For example, the string for PHP 5.5 on Ubuntu is “5.5.16+dfsg-1+deb.sury.org~precise+2”.

Now, you can run the apt-get install command with the specific version number, and voila!

sudo apt-get install php5=5.5.16+dfsg-1+deb.sury.org~precise+2

I only added this because I was unable to find this information anywhere else!

Answer #6:

On Ubuntu 9.04 Jaunty,

apt-get --only-upgrade install <package>

yields:

E: Sense only is not understood, try true or false.

The command

apt-get --only-upgrade true install <package>

worked in my case.

Answer #7:

For a command line solution that doesn’t install the package if it doesn’t already exist:

dpkg -s <package> 2>/dev/null | grep -q Status.*installed && sudo apt-get install <package>

This can easily be made into a script, e.g.:

upgrade-package.sh:

#!/bin/bash

[[ -z $1 ]] && { echo "Usage: $(basename $0) package"; exit 1; }

if dpkg -s "$1" 2>/dev/null | grep -q Status.*installed; then
    echo "Attempting to upgrade $1"
    sudo apt-get install "$1"
else
    echo "Package $1 is not installed"
fi

How to upgrade a single package using apt-get in Ubuntu?

To upgrade a single package on Ubuntu 18.04 LTS:

sudo apt update && sudo apt install --only-upgrade <packagename>

To upgrade multiple packages:

sudo apt update && sudo apt install --only-upgrade <package1> <package2> <package3>

Hope you learned something from this post.

Follow Programming Articles for more!

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →