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?
just type
And the latest available in all your repositories will be installed.
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: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
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=\*
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.