Asking for a letter of recommendation from professor that offered me a position I am currently an undergraduate in Computer Science, and I am seriously thinking about getting a PhD (I have to apply next year, and I like to do my homeworks way beforehand).

Last year I worked as an assistant researcher in a group at my university. Everybody was really pleased with my work and they said they would be very happy to have me as their student, including the head of the group (he was also one of the professors of some undergraduate courses).

The problem is, while my School is quite good, and I wouldn't mind at all to pursue my degree in this group, I would like to try other opportunities. This would imply requesting a letter of recommendation from him.

Is there any way to suggest that I want to try to apply somewhere else (quite objectively a better grad school, in a different country) and, if that fails, I would like to stay in his group, without being rude? How would this be perceived?
To your first question, yes.  There's nothing inherently rude about wanting to look for positions elsewhere despite having an offer.  Professors often want to their top students to stay on for graduate work, but these students often go to other, often better, schools (or don't pursue graduate studies) so your situation is completely normal.  Most professors wouldn't be offended by such information.  (There may be some cultures where professors' expectations are different, but not the ones I know about.)

I would suggest a frank discussion where you say that, while you'd be happy to continue your studies under that professor, there are some other schools in other countries you're interested in.  There's no need to tell him now, but if it comes up again, there's no need to withhold it either.  You can also bring it up as a question to see if he has any advice: "Yes, I'll probably apply to the program here, but I'm also thinking about trying to study at XXX--what do you think about that?"