It depends on your platform, and there are a bunch of ways to do it.
On Mac OSX, there is a built-in QuickTime screen recorder.
- Launch QuickTime Player
- File menu -> New Screen Recording
- Use the tool of your choice (such as ffmpeg) to convert the recording to a gif.
Here's an example of how to convert a recording .mov file to a gif:
ffmpeg -i in.mov -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif
See this link for more info and step by step: https://gist.github.com/dergachev/4627207
If you're on other platforms, or prefer to use a specific tool other than the built-in QuickTime, here are a few to consider:
- Grabilla Firefox Add-On
- Animated GIF Capture Chrome extension
- LICEcap for Windows and OSX