29

It's easy to install a specific version of a package with apt-get:

apt-get install <package name>=<version>

For example:

apt-get install jenkins=1.517

But is there a shortcut for installing the latest version?

For example, say writing a script to automate Jenkins installation. After adding http:/q/pkg.jenkins-ci.org/debian to /etc/apt/sources.list, Jenkins is available from two sources. Now, I'd like to tell apt-get to install the latest version without knowing exactly what the latest version is at the time the script is executed.

Is this possible in any simple way?

1
  • apt-get by default get the latest version. run apt-get update before to be sure
    – Anwar
    Commented Jun 27, 2015 at 5:20

5 Answers 5

19

just type

apt-get update    
apt-get install <package-name>

And the latest available in all your repositories will be installed.

2
  • 3
    Don't forget apt-get update before apt-get install ... to update the package lists from repositories. Commented Jun 3, 2013 at 13:13
  • Thanks, kind of obvious... :) Earlier I've run into having an older version installed unintentionally, but maybe that was caused by forgetting to do apt-get update first.
    – Jonik
    Commented Jun 3, 2013 at 14:21
14

The selected answer works in most cases. However, you might find yourself in a situation where a more recent version is available in a backport repository which will not be installed by apt-get install <package-name> by default. For example, I recently came across this:

$ apt-cache policy golang
golang:
  Installed: 2:1.3.3-1
  Candidate: 2:1.3.3-1
  Version table:
     2:1.7~5~bpo8+1 0
        100 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages
     2:1.5.1-4~bpo8+1 0
        100 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages
 *** 2:1.3.3-1 0
        500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status

Selecting a version from the backports can be done by specifying to install from backports: apt-get -t xenial-backports install golang.

Reference: https://help.ubuntu.com/community/UbuntuBackports#Installing_Backports

7

For anyone else that lands here: ttoine's answer is correct.

BUT if you are stuck with the apt-get -q -y --force-yes install openjdk-6-jdk=<blah> syntax (let's say via Chef), you can specify an asterisk/star to get the latest: apt-get -q -y --force-yes install openjdk-6-jdk=\*

2
  • What about if a package name has a version number? e.g. older versions of ubuntu have libgdbm5 newer ones have libgdbm6. Is there a way to install whichever's available?
    – Harry Wood
    Commented May 26, 2021 at 14:26
  • Actually I'll ask my libgdbm5 or libgdbm6 problem a new question
    – Harry Wood
    Commented Jun 7, 2021 at 10:54
2

Note that to get an actual latest version of a package, you may need to add a repository to apt, a repository that holds a more current (i.e., real latest) version of the package. E.g., the openvpn documentation explains:

"Latest OpenVPN releases are available in the OpenVPN project's apt repositories. This allow you to use more up-to-date version of OpenVPN than what is typically available in your distribution's repositories."

Of course, you want to make sure you trust any repository you add. There are various ways to add a repository. I like the way they suggest in the OpenVPN docs linked above. There's also add-apt-repository.

0

This works for packages that were installed using apt-get:

apt-get update <package-name>

But if you install an app from a GitHub repository that publishes their content on a release basis, the apt-get update won't work as it is not part of the Ubuntu/Debian ecosystem.

You need to re-install the package.

Please see the instructions on the package repo, but usually if you re-install the package it will get updated.

Check the version before and after the re-install to make sure your package was updated correctly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .