430

How can I downgrade a package to an older version via apt-get?

Other tools are also acceptable but apt-get is preferred.

Zanna
  • 70,465

6 Answers6

411

If you have the version number, or the target release, apt-get supports choosing a particular version or target release. More details can be found on manual page of apt-get. It can also be accessed from terminal by typing man apt-get

sudo apt-get install <package-name>=<package-version-number> OR

sudo apt-get -t=<target release> install <package-name>

is the command to be run. This can be used to down-grade a package to a specific version.

Remark that when using a target release (option -t), the release priority must greater than 1000 to allow downgrades (see man 5 apt_preferences) otherwise the currently installed version will be kept.

It has been helpfully pointed out in the comments that

  • apt-cache showpkg <package-name> lists all available versions. (h/t Sparhawk)
  • apt-mark hold <package-name> "holds" the package at the current version, preventing automatic upgrades. (h/t Luís de Sousa )
muru
  • 197,895
  • 55
  • 485
  • 740
Mahesh
  • 12,738
174

Use:

apt-get install «pkg»=«version»

or:

sudo aptitude install «pkg»=«version»

Where:

  • «pkg» is the name of the package.
  • «version» is the version number.
  • 5
    when i type apt-get install pkg=version apt-get offers removing almost half of all installed packages which of course not what i want to do – Dfr Jul 15 '15 at 08:38
  • 4
    As pointed in the (otherwise identical) answer with more votes, this seems to be one of the key cases where aptitude does a much better job than apt-get. In my case apt-getflatly refused the downgrade request, whereas aptitude pointed out that there were other pkgs which depended on the newer version (and thus needed downgrading at the same time). – sxc731 Apr 12 '18 at 18:02
  • 4
    Hint: run apt list -a <pkg> to find out what versions are available – Nero Vanbiervliet Sep 20 '21 at 09:20
39

If you have upgraded software using ppa you can downgrade it by using ppa-purge. First you have to install ppa-purge using this code:

sudo apt-get install ppa-purge

Then you can remove the ppa using command

sudo ppa-purge ppa:user/ppa-name

this will automatically downgrade the software to its original version which shipped with Ubuntu.

Apurba
  • 1,438
  • 2
    This solution is just unmatched in case the package has dependencies which also have to be downgraded. Thanks! – and Aug 10 '17 at 10:27
  • 2
    Yes this is the solution that worked best for me for downgrading KDE/Plasma desktop from kubuntu-ppa/backports - one thing I noticed is the PPA's .list file must not have the deb commented out, so ppa-purge can reference all the files that need to be removed for the purge. Took me a minute to figure out why it wasn't working at first. Hope that helps other people! – Avery Freeman Aug 23 '19 at 20:24
16

In my opinion, you should first uninstall or purge the package, like:

sudo apt-get remove <package>

or

sudo apt-get purge <package>

Then, you may download the version you would like to install and keep it in a folder, say abc.deb in Downloads. Open terminal, move to the folder using cd command and install the previous version using dpkg:

sudo dpkg -i abc.deb

Or else, there is a small utility called ppa-purge if you mean to downgrade packages updated via PPAs.

See this thread: http://www.webupd8.org/2009/12/remove-ppa-repositories-via-command.html

  • 6
    removing a package may remove many dependent ones, resulting in an unusable system. ppapurge sounds interesting though. – type May 20 '12 at 19:04
  • 15
    Can you explain why you believe we ought to first uninstall packages (as a separate step) before installing older versions of them? – Eliah Kagan Oct 04 '12 at 20:48
  • http://permalink.gmane.org/gmane.comp.sysutils.puppet.devel/23219 – temoto Oct 01 '13 at 06:10
  • 1
    @temoto that link is for downgrading releases unstable -> testing -> stable not to downgrade individual packages. – Braiam Oct 09 '13 at 17:50
15

To downgrade you have to do a command like

 sudo apt-get install pkg_name=version

in your terminal.

In the place of version put the previous version you want to downgrade to.

Eliah Kagan
  • 117,780
Raja G
  • 102,391
  • 106
  • 255
  • 328
  • 2
    It doesn't work at least for linux-generic which depends on packages that should be downgraded too. I get https://paste.ubuntu.com/p/NWSmf2ZwTy/ – mymedia Jan 08 '19 at 20:18
  • Some depending packages may have to be purged before installing a specific version of the desired package... – m13r Apr 27 '21 at 12:20
  • @mymedia linux-generic is a meta package, not a package. Kernel packages in ubuntu always have a version as part of the package like linux-image-5.15.0-100-generic with version 5.15.0-100.110~20.04.1 i.e. linux-image-5.15.0-100-generic-5.15.0-100.110~20.04.1. So kernel packages are never updates, but independently named packages. This allows for multiple versions of the kernel to be installed together. It also *doesn't break the system by removing mods of the running kernel* . Your issue is that you tried installing separate kernel packages with conflicting dependencies. – Samveen Mar 21 '24 at 04:31
11

This question is old but Google led me here and I didn't find simple solution that does't require manual version passing when downgrading a bunch of packages to an older release.

So maybe someone who also needs that will find my solution useful as well.

There's a tool called apt-show-versions that shows versions installed. To install it:

$ sudo apt install apt-show-versions

Make sure APT's cache is up to date:

$ sudo apt-show-versions -i

You can easily downgrade all required packages by fine-tuning the regex but here it is:

$ sudo apt-get install $(apt-show-versions \
   | grep -P 'newer than version in archive' \
   | awk -F: '{print $1"/'$(lsb_release -cs)'"}')

You should have lsb-release installed for the latter.

slm
  • 3,035
gudvinr
  • 149
  • 1
  • 6
  • 2
    Or automatically downgrade to up-to-date installed release: sudo apt-get install -V $(apt-show-versions | grep -F 'newer than version in archive' | awk -F: '{print $1"/'$(lsb_release -cs)'"}'). I prefer using -F for grep here. – jarno Sep 15 '19 at 22:24
  • 1
    Thank you, this is incredibly helpful! – Zulakis Oct 10 '20 at 14:26
  • @jarno thanks for the incantation; I adjusted it to work for packages that come in multiple arch flavors on the same platform (e.g. libc6): sudo apt-get install -V $(apt-show-versions | grep -F 'newer than version in archive' | awk -F' ' '{print $1"/'$(lsb_release -cs)'"}') (just change the separator for awk from colon to space). – Reuben Thomas Oct 20 '21 at 14:43