The literary history of Gilgamesh begins with five Sumerian poems about Bilgamesh (Sumerian for "Gilgamesh"), king of Uruk, dating from the Third Dynasty of Ur (c. 2100 BC). These independent stories were later used as source material for a combined epic. The first surviving version of this combined epic, known as the "Old Babylonian" version, dates to the 18th century BC ... Only a few tablets of it have survived. The later "standard" version dates from the 13th to the 10th centuries BC ... Approximately two thirds of this longer, twelve-tablet version have been recovered.
From the diverse sources found, two main versions of the epic have been partially reconstructed: the standard Akkadian version, or He who saw the deep, and the Old Babylonian version, or Surpassing all other kings. Five earlier Sumerian poems about Gilgamesh have been partially recovered, some with primitive versions of specific episodes in the Akkadian version, others with unrelated stories.
Thus, if you want to read what is typically termed the Gilgamesh Epic, you need to learn Standard Akkadian or Old Babylonian, not necessarily Sumerian. Standard Akkadian is a later stage of Old Babylonian. Old Babylonian is highly regular which makes it a good starting point; from there you can learn Standard Akkadian by learning about the developments. The other direction is more complicated. Still, the Gilgamesh Epic is a literary work and it will take time before you can read it; in my university students of Old Babylonian start with the Codex Hammurabi. You can read the texts in transcription, or else you need to learn the cuneiform signs, which also differ per period.
Sumerian is a language isolate that had a lot of language contact with the precursor of Old Babylonian (cuneiform is originally Sumerian). It is perfectly possible to learn Akkadian without knowledge of Sumerian, but if you are interested in the Sumerian poems you clearly need to learn it.
While Akkadian is an East Semitic language, Ugaritic is a North West Semitic language, as far as I know not directly related to the Gilgamesh epic. It is genealogically closer to Ancient Hebrew and Old Aramaic or even Arabic than to Akkadian (although, like Akkadian, it features nominal cases which Hebrew and Aramaic do not). Perhaps you thought it is related because it is also cuneiform? But cuneiform is a generic term for writing incised on clay tablets. The cuneiform of Akkadian of different periods uses different signs, and like that Ugaritic is yet another writing system, with the most important difference that Ugaritic writing is alphabetic while Akkadian is syllabic.
Let me know if you want textbook suggestions and if so for what.