Yes, you can learn how to write songs. Provided you have a topic you care to write a song about, and you have basic music knowledge (writing a song means both music-basic vocal line and backing harmony and lyrics).
Basic music knowledge means, some fundamental skills on an instrument, like piano or other keys, ukulele or guitar, and basic chord functions.
There are on line tutorials on coursera, provided by Berklee staff, and lots of songwriters that teach (well, like myself).
Nowadays, there are also Bachelors and Master's degrees in Songwriting, if you care to pursue it further, and lots of books to assists you. You can also study the songs you really love, analyse them and try to learn from them (yes, copy from them).
Lia Hide is a singer-songwriter, producer, music educator, and multi-instrumentalist. Her debut album was released by EMI, she then decided become an independent artist, besides that she wrote music for a Greek theatre. Lia performed in major festivals worldwide alongside acts like Tricky, Molly Nilson or Kovacs. She also studied piano, opera, musical theatre and popular music vocals, and songwriting and has been teaching these subjects since 2002.