After having tried multiple different methods of trying to take a screencast and save it as a gif I have come to the conclusion that LICEcap (so far) is the best for Linux. Ultimately, I don't think there is one really good way to save animated gifs in Ubuntu or Linux, but LICEcap comes the closest.
Right now if you were to look for a tutorial for how to do this in Linux, most sites suggest using video screencasting software (like Recordmydesktop, Kazam, or Byzanz) to get a video, then use ffmpeg in the terminal to convert it to a gif. There are some other programs that skip the gui process altogether and just use the command line to get the screencast gif. These programs such as Kgif or SilentCast usually work with Scrot as a dependency to get your gif. If you are a terminal lover, then these might be the way to go, but if you are like me and enjoy the ease of a gui, we unfortunately have to turn to Windows software.
By far, the best software I have used for getting a gif screencast is ShareX. Unfortunately, ShareX does not (and probably never will) work correctly in Wine. LICEcap on the other hand works wonderfully in Wine.
You can download LICEcap here.
Once you have the Windows executable downloaded, you can install it using Wine. I prefer to do this using PlayOnLinux. Once you have this installed, you can simply run and use LICEcap just as you would in Windows.
Here is a gif I recorded using LICEcap:
For full instructions and a demonstration on how to install and use LICEcap, please checkout this video I made: