1023

How do I update a single package? As far as man apt-get says apt-get upgrade doesn't take a package/list of packages as parameter:

upgrade

upgrade is used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list. Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version. An update must be performed first so that apt-get knows that new versions of packages are available.

karthik
  • 279
  • 1
  • 3
  • 16
lurscher
  • 11,085
  • 5
  • 22
  • 27

7 Answers7

1272

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.

John M.
  • 103
  • 3
Josh
  • 12,851
  • 1
  • 13
  • 4
  • 2
    @Raphink: Your comment about the upgrade is right, but install is considered as an equivalent to upgrading one package; `install is followed **by one** or more packages desired for installation or upgrading` , If you have a better answer, you can answer the question.It would be great. – Binarylife Aug 04 '11 at 11:56
  • 99
    `apt-get install --only-upgrade ` will not install any new packages – taneli Oct 15 '12 at 11:29
  • 12
    Will the `install` command upgrade also the dependencies of that single package if necessary? – Pino May 31 '13 at 08:18
  • 11
    @Pino It will, it makes sense to do so. What if the version you are upgrading to depends on a newer version of another package? You're hosed if you don't upgrade both. This is why `install` is the right command for this, even if it seems counter-intuitive. – Matt Dodge Aug 22 '13 at 19:57
  • Do you need to restart after updating? My package is still showing the same version? – CMCDragonkai Apr 09 '14 at 06:16
  • 1
    Assuming dependencies are upgraded too, will that break applications using shared dependencies ? – Ahmed Apr 04 '15 at 00:40
  • 10
    Does this remove the "auto" mark? Sometimes when you install libraries specifically the package is marked as manually installed. I don't like running 'install' on libraries for this reason. – isaaclw Sep 29 '15 at 16:24
  • Works with Ubuntu 16.04 as well i mean `apt install --only-upgrade install ` – Nasik Shafeek Sep 07 '16 at 03:09
  • 2
    `--only-upgrade` is useless here. `install` solely will upgrade the package – Anwar Nov 01 '16 at 07:03
  • 6
    I just tested, since all information is pretty vague; on Ubuntu 16.04 (`apt 1.0.1`), upgrading a package using `apt install` does not affect the `auto` mark, whether `--only-upgrade` is supplied or not. Though of course using `--only-upgrade` makes sense if you don't want to accidentally install something new. It will also upgrade any *required* dependencies. – dualed Aug 23 '18 at 13:01
  • 1
    @isaaclw adding `--only-upgrade` flag ensures the package isn't set to manually installed (Ubuntu 20.04) – Fadi Feb 05 '22 at 17:12
  • @Anwar it's definitely not useless, see my previous comment – Fadi Feb 05 '22 at 17:25
150

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.
muru
  • 185,114
  • 48
  • 449
  • 695
Ian
  • 1,525
  • 1
  • 9
  • 2
  • 12
    I get an error with this command: `E: Sense only is not understood, try true or false.` – Michael Sep 20 '13 at 18:15
  • 1
    For those who encounter the previous commentator's error see [my answer below](http://askubuntu.com/questions/44122/how-to-upgrade-a-single-package-using-apt-get/608859#answer-608859). – golem Apr 13 '15 at 18:23
  • 4
    downvoted as it did not add new information from previous answers – gokul_uf Mar 22 '16 at 23:55
  • 1
    You should pass `--only-upgrade` to `install` subcommand, not directly to `apt-get`, then you'll not have to append `true`. – Ruslan Mar 23 '17 at 09:58
69

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 Manager: Right click→Mark for upgrade:

    enter image description here

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

svick
  • 142
  • 6
Binarylife
  • 16,094
  • 10
  • 54
  • 65
  • 1
    Yeah , it should , and `sudo apt-get install whatever` should do upgrade by itself. – Binarylife May 20 '11 at 16:44
  • 4
    `upgrade` doesn't take a package argument. – raphink Aug 04 '11 at 11:31
  • `sudo apt-get install nameofpackage` will upgrade, but also set the package to "manually installed" in case it was installed as a dependency only. That is not always desired, as it limits the usefulness of `sudo apt autoremove` later. – tanius Jun 19 '20 at 11:17
28

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!

chopsuei3
  • 389
  • 3
  • 2
  • I suppose this is obvious to some, but if the above `apt-get install` command fails with a message like `Unable to fetch some archives`, you may need to run `apt update` first, then rerun `apt-cache policy` to identify the correct version for the final `install` command. – CODE-REaD May 20 '20 at 19:29
16

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.

Eliah Kagan
  • 113,757
  • 52
  • 310
  • 478
golem
  • 269
  • 2
  • 6
  • 10
    You should pass `--only-upgrade` to `install` subcommand, not directly to `apt-get`, then you'll not have to append `true`. – Ruslan Mar 23 '17 at 09:58
10

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
Shane
  • 201
  • 2
  • 2
2

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>
supercontra
  • 501
  • 4
  • 7