emerge: downgrade package

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

Say you want to downgrade mysql from mysql 5.6 to mysql 5.5.
The basic workflow would be:

// Remove currently installed package:
# emerge -C dev-db/mysql
// Check what versions exist:
# equery meta dev-db/mysql
...
// Emerge the exact version you want:
# emerge -a =dev-db/mysql-5.5.54
// Mask greater versions, to prevent an automatic upgrade:
# echo ">dev-db/mysql-5.5.54" >> /etc/portage/package.mask

In theory, it's easy. However, downgrading is generally not recommended. It may result in various SLOT conflicts, which may or may not be easy or possible to resolve.

Please add here tips and guidelines on possible strategies to try resolving slot conflicts.

To resolve conflicts, try:
- check man emerge for --depclean. Remove all the packages depending on the just removed package.
- make sure that none of the packages are mentioned in your world file. Delete them from there if necessary.
- equery depends, emerge --depclean --pretend --tree package
- check your USE flags for potential conflicts.
- Consider FEATURES="buildpkg" in make.conf to go back to a previous build version.

- Make precise notes of all the conclicts. Use the --verbose-conflicts flag:

# emerge -a =dev-db/mysql-5.5.54 --backtrack=30 --verbose-conflicts

- For each package, make sure that there is an ebuild that would work with the downgraded package.
- Unmerge each of the conflicting package. Depending on what you are trying to downgrade, this may render parts of your system unusable.
- Downgrade the package, then re-emerge each package you had to unmerge in the previous step. Update package.use and package.mask accordingly.

demerge

// Install demerge:
# emerge --ask app-portage/demerge
...
// Record current state:
# demerge --record --comment="Trying to downgrade mysql"
// Try to downgrade system.
...
// If necessary, restore system to previous state:
# demerge --restore-previous