How to install the latest version of a package with apt-get?
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.517But is there a shortcut for installing the latest version?
For example, say writing a script to automate Jenkins installation. After adding http:/q/ 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?
14 Answers
just type
apt-get update
apt-get install <package-name>And the latest available in all your repositories will be installed.
2The 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 xenial-backports/main amd64 Packages 2:1.5.1-4~bpo8+1 0 100 xenial-backports/main amd64 Packages *** 2:1.3.3-1 0 500 xenial/main amd64 Packages 100 /var/lib/dpkg/statusSelecting a version from the backports can be done by specifying to install from backports: apt-get -t xenial-backports install golang.
Reference:
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.