Gems are the premium currency in Clash of Clans. This means that generally, in order to earn them, you have to spend real money. Gems are required primarily to avoid you havinng to wait for things to finish production. Clash of Clans is very stingey when it comes to Gems, as the wait times for the majority of things in the game are quite prohibitive.
Certain things can only be done with Gems, such as purchasing more builders. Gems are also given for completing achievements, with a certain number rewarded for each. This is the best way to get more. You begin the game with lots of them, so it can seem like you should be spending as many as you like - but early on especially you should save them and ignore when the tutorial tells you to use them. You can also use Gems for purchasing a Shield, for 1 day, 2 days or 7 days. If you are impatient for resources, you can also purchase those.
Very occasionally, you will also unearth Gems when you clear up the stones, trees, mushrooms and stumps around your village.
By far the best thing to spend Gems on, if you have the patience, is Builders Huts - making sure you have 2, 3 and eventually 4 of these is undoubtedly the best way to go in terms of spending your Gems.
The best way to get Gems is to complete the Achievements listed. The higher level the achievement, the more Gems you will get.
Gems are awarded for completing in game achievements