It is necessary to emphasize that neither apt-get autoclean, nor aptitude autoclean delete older versions, but remove obsolete packages, which are not present in the repository anymore.
Moreover, the scripts proposed in other answers ignore packet's architecture, meaning that if you have packages with different architectures only one will be preserved and others deleted
I.e. none of the available answers provide a comprehensive solution. Thus, here is a command line as an alternative to other answers:
$ basename -a /var/cache/apt/archives/*.deb | cut -d _ -s -f 1,3 --output-delimiter=_*_ | uniq -d | xargs -I{} sh -c "find /var/cache/apt/archives/ -maxdepth 1 -name {} -print | sort -V | head -n -1" | xargs -r sudo rm
Explanation
basename -a /var/cache/apt/archives/*.deb
lists all filenames without their full path.
cut -d _ -s -f 1,3 --output-delimiter=_*_
replaces package version with asterisk (*) keeping base package name (prefix) and its architecture (suffix).
uniq -d
drops duplicate entries and simultaneously drops entries without duplicates.
xargs -I{} sh -c
for every entry executes command enclosed in quotes and substitutes {} pattern with the input file mask.
find /var/cache/apt/archives/ -maxdepth 1 -name {} -print
executes non-recursive search in the archive directory for the target pattern printing result to the standard output.
sort -V
sorts results for every search.
head -n -1
drops the last result, i.e. the one with the numerically highest version (other results will be removed in the end, but the last one will stay).
xargs -r sudo rm
puts results from all searches together and passes them to the remove command executed with super-user privilege.