If you only have state pension you don't really need to do anything if you stay in the EU when you retire.
Once you reach the retirement age in the country you have last worked (which might be different to the one where you are resident, in case you never worked there), then they will calculate your pension based on two different ways:
Option 1: National rate
This means they will calculate how much pension you'd receive in each of the countries if you'd never worked in any other country, and sum these together. So if you have 10 years of UK coverage 5 years of Spanish and 20 years of German they would calculate how much you'd receive in the UK after 10 years, how much you'd receive in Spain after 5 and how much would you get in Germany for 20.
Now, this amount might actually be 0, as in most countries you have to work for many years before you are entitled for state pension. That's why there is option 2:
Option 2: EU-equivalent rate
This means they will assume you have worked in each country the total amount of time (in our example 35 years), and will check how much you'd get in each of the countries for 35 years of coverage, and will calcualte the actual amount pro-rata.
After calculating how much you'd get for each option, you will get the one which is the higher.
You can find more info about this EU scheme on europa.eu.
The above only applies for state pensions, and you have to retire in the EU.
You might also have some other kind of pensions, for example in the UK it is common that you also get some kind of Workplace Pension Scheme. These schemes have their own regulations on how you can get your money. See this answer for more info. You might also have some kind of supplementary state pension, for which this EU rule applies.