Both variants are correct, there is simply difference in tone, not in meaning:
Both gerunds and infinitives can be used as the subject or the
complement of a sentence. However, as subjects or complements, gerunds
usually sound more like normal, spoken English, whereas infinitives
sound more abstract. In the following sentences, gerunds sound more
natural and would be more common in everyday English.
Infinitives
emphasize the possibility or potential for something and sound more
philosophical [another site says more formal and literary]. As a rule of thumb a gerund is best most of the time.
- Normal subject: Learning is important.
- Abstract subject: To learn is important. (EnglishLgeCenters)
SageJournals has an article that denies what the local English teachers claim:
This corpus-based study shows that the distinction between the gerund and the infinitive cannot be accounted for in terms of the previously proposed oppositions between particularity and generality.
I wish we had access to the whole article. Here you will find some tips for using gerunds and infinitives. That gerunds are more common than infinitives is backed up by this Ngram.