You can use the Peek program to record and create a GIF for you.

First install Peek the usual way:

$ sudo apt install peek

Run the Peek application and resize it to be just cover the window or area you want to record.

Then press Record as GIF!

You can reduce the size of your GIF using the gifsicle command:

$ gifsicle -i original.gif -O3 --colors 256 -o optimized.gi

You can reduce even further the final size case you are recording terminal sequence tutorials where we don’t have many colors (normally black and green in my case).

$ gifsicle -i original.gif -O3 –colors 16 -o optimized.gif