A patent is a temporary legal monopoly on an invention, which grants to the holder the legal right to exclude others from making, using, selling, offering for sale, and/or importing that invention (source) or anything which embodies it. In most countries, the concept of "invention" now unfortunately includes ideas expressed in software.
How can I get in trouble by installing a open source or free (FSF) software package? Is this because the idea of an opensource software might be patented?
Nearly; it's because the free software might embody one or more inventions which are covered by a live patent. However, in practice you're unlikely to get into trouble; see below.
What about developers of that software? What about package maintainers, why patent does not affect them?
In brief, it does; however, patent lawsuits are notoriously expensive. That's fine if you're suing a big company with deep coffers, as if you win you'll likely get your costs covered. If you're suing Fiona Q. Hacker for publishing some code on gitlab, then even if you win and get a costs award, odds are you'll never recover the money. Meanwhile, seventy-three people will have forked her repo and be publishing similarly-infringing code. That's not to say the occasional patent troll doesn't pump out cease-and-desist letters to poor starving free software developers, but it's not that common, because it's not very effective. Big companies involved in free software, however, are very careful not to knowingly violate existing patents.
Is there any version of these packages shipped without patented codecs?
That's package-specific, but in some cases it's effectively impossible, because the software exists solely to implement a patent-encumbered standard. The tendency of international standards bodies to standardise on patented technologies whilst only requiring the patent to be licensed on reasonable and non-discriminatory terms doesn't help. (To be clear, I would prefer to see bodies like W3C and the ITU mandate that anyone applying for a technology to be standardised agree to abandon any patents they hold on it if the application was approved).
What happens if I install them in a country not affected by patents and then move to an effected one?
Patents include the right to control import, so that's a no-no.