Most MMOs have some sort of beast-taming class, and Guild Wars 2 is no different. The ranger can tame wild animals and use them in combat, allowing them to stay back on the edges of battle and pelt their foes with ranged attacks. It's a simple dynamic, but there are over 50 different trainable creatures in the game, so tracking them down, learning their skills, and picking which one is most suitable for the given moment will be a time-consuming, if fun, process!
Every ranger begins with a single pet, but you're likely to find many more in your travels. To train a new pet, you'll want to look for wild animals in the world and search for anything that's listed as a "juvenile" version of that animal; these will usually be green, friendly NPCs, so you won't have to worry about other people attacking them. When you find one, just walk up to it and interact with it to add it to your stable.
You can find small bands of juvenile animals in most race's starting zones, if you're looking for something to train. Each variety of pet will have different attributes and attacks, so you'll want to train as many animals as you come across. Generally speaking, animals with a large amount of toughness and vitality are probably going to be most useful to you as you level up, since they'll be better able to withstand the pressures of the sometimes large battles you'll find yourself in. You can switch between different animals via the pet management menu, which is bound to the K key by default. The top two animal slots are for land encounters, while the bottom two will determine which pets you can use while underwater.
Look for juvenile animals out in the wild to train new pets.
When you have a pet by your side, you can use your F1 key to send it out to attack an enemy before you do so yourself, or you can let it wait for you to attack; it'll automatically move to kill your target when you fire a shot. You can also use the F2 key to use your pet's special ability, which you can read about by mousing over the icon in the pet bar above your skill bar.
Note that you can switch between pets at any time via the F4 key, or the small arrow icon on your pet bar. You can do this in combat, and should take advantage of that fact: you can switch between a downed or wounded pet and instantly pop out a completely healed one via pet switching. There is a cooldown on this button if you switch pets in combat, though, preventing you from simply mashing the button for an infinite supply of healthy pets.
The ranger can boost their Pet Attribute Bonus via their traits, which will boost all the power, toughness, vitality, and so on of your pets.