27

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?

Jonik
  • 7,178

5 Answers5

18

just type

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

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

ttoine
  • 1,160
  • 3
    Don't forget apt-get update before apt-get install ... to update the package lists from repositories. – Eric Carvalho Jun 03 '13 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 Jun 03 '13 at 14:21
13

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

jotrocken
  • 342
6

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

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.

Hawkeye Parker
  • 535
  • 5
  • 6
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.