In English we have ways of making verbs act like a noun, we can use the gerund or the infinitive.
“run”, “swim” and “think” are verbs.
“running”, “swimming” and “thinking” are gerunds.
“to run”, “to swim”, and “to think” are infinitives.
We usually use gerunds for sentences about real things and actions.
“I went running yesterday” the action of running
“Swimming is so difficult” the action of swimming
“I stopped thinking about her” the action of thinking.
We use infinitives more for abstract ideas, or future actions. Things that aren’t real, or aren’t real yet.
“I want to run in a marathon.” a desire, not a real action yet.
“I plan to swim the entire lake” a plan, not a real action yet.
“The purpose is to think hard about your answer.” purpose is an abstract idea.
Sometimes though, when talking about preferences, both gerunds and infinitives work fine.
“I like swimming.” The action of swimming.
“I like to swim.” The concept of swimming.
Both sentences have the same meaning.
So for preferences, such as “Like”, “Love”, “Hate” and “Prefer” feel free to use either one.