There is no right way to learn guitar or music for that matter.
If you want to be able to make your own music, then start writing music! Again there is no right or wrong way, but there are certain things that you can do to improve your songwriting and become better at the craft.
First and foremost, the most important thing to do is start writing. You make no mention of how long you've been playing guitar or what sort of music experience you have, nor did you mention whether or not you wish to write songs that are sung or instrumentals.
Some of the most important things for you to know when beginning song writing is chords and scales. I started writing my first song within the first few minutes of picking up a guitar. My friend taught me Eminor and Amajor and the rest is history! Learn some chords and start putting them together and try to come up with melodies to them. Some people will suggest coming up with a melody first and then adding chords to it afterwards, but I feel that coming up with the chords first is easier especially when you're just starting out, since it gives you a bit of constraint.
Learn as many major/minor chords as possible, and definitely learn barre chords. Look up chord progressions and begin by writing songs with generic chord progressions that are popular. Namely start with writing a few songs that use the I, IV, V progression. After you've written a few songs using pre-established chord progressions, start trying to come up with your own chord progressions and then create melodies to that.
Learn about scales and their relationships to chords and chord progressions.
Once you feel that you're ready, start coming up with melodies and then picking chords that go well with the melody.
In order to learn how to write songs, you have to do it often, and be prepared to write some bad music before you start writing some good stuff. A lot of people learn music by imitating the music of others first. It's a great way to learn. I learned music by songwriting. I knew that I wanted to write songs more than I cared about being a great instrumentalist or being able to play the songs of others, so that is what I focused on. Alfred's Essentials of Music Theory is a great starter text and should provide you with some decent musical foundation. I wrote at least a dozen songs before I tried to learn any covers, so there is no right or wrong way. Just start writing and learn songs that really interest you so that you can obtain techniques from them.