I am habituated to use ubuntu system.
I have an Imac and I want to install her ubuntu.
is it legal to do it?
Thanks in advance.
There is no question of legality. The licensing of the software in Ubuntu does not restrict the hardware on which it can be installed. The only restrictions are technical (is your computer the same architecture, is the boot system handled in the normal way, etc…).
You didn't say which iMac you have, but if it is a PowerPC machine, it may be more troublesome, as more modern versions of Ubuntu aren't as well supported on PPC any longer. Also, some apps are heavily dependant on x86 optimizations, and may not be available on PPC at all (depending on what you are wishing to do with the machine). For basic usage, you should be fine, though.
If it's a newer Intel iMac, then of course it should work better, and you will be able to do more with it.