Purchase a largest possible tank for your goldfish. While using a 10 liter (L) tank instead of a small bowl will increase longevity, albeit not by much, 40 liters/fish or more is necessary for quality of life. Choose a tank with large surface area to increase amount of oxygen in contact with the surface of the water (i.e., wider is better than taller), or set up a pond for your goldfish.
Set up the tank prior to the purchase of fish. Getting it ready may take two or more weeks. It is necessary to build up enough good bacteria to break down the fish' wastes. To do this, do a "Fishless Cycle". Once completed, your goldfish aquarium will have more than enough bacteria to break down fish waste. Failure to cycle a tank will result in ammonia poisoning and death.
Provide mental and physical stimulation for the fish. Decorate tank with gravel, bridges, plants, etc. Gravel provides a place for good bacteria to grow, and goldfish like to hide and swim through little buildings and bridges. Rearrange the bridges and plants on a monthly basis to offer the goldfish "new" areas to explore. You can also train your fish to stimulate them. If you feed them at the same time every day, they will soon be waiting for you at that time. You can also use a fish net with the netting taken out as a 'hoop' and train your fish to swim through it.
Add a filter. You can use either a large internal or an external filter. An external is usually the best, as goldfish are very messy creatures. Without a filter, smaller tanks will foul and become deadly in just a day or two. Keep in mind that having a filter doesn't mean you can avoid cleaning the tank. Even with a filter, change 20% to 30% of the water about once every week.
Add some equipment to increase oxygen diffusion into the water. A small air pump and air stone will be sufficient.
Clean the tank at least once every two weeks, but more frequently is preferable due to the large amount of waste goldfish produce. This is essential. How often you do this will depend on the size of your tank, the number of fish, and the effectiveness of the filter. Also, if you have real plants they will help absorb some of the ammonia, nitrites and nitrates. So if you have real plants, you don't need to clean as often.
When you add/change water, use a dechlorinator that also removes chloramine and heavy metals as per instructions on the back of the bottle.
Frequently test for ammonia and nitrite. A pH test is also handy to ensure your goldfish's water is not too alkaline or acidic. This can be purchased at any pet store. Do not modify the fish's water, however, unless it is significantly different from neutral. Goldfish can tolerate a wide pH range, and pH modifying chemicals are not a lasting solution without more consistent monitoring than most people will do. A range of pH 6.5-8.25 is fine. Many municipal water supplies buffer their water up to around 7.5, and goldfish will live very happily in this range.
Do not remove the goldfish during a water change. Using a gravel vacuum to suck debris out of the gravel can be done with the fish in the tank. Frequent partial water changes are better than full (and stressful) water changes.
If you do need to catch your fish, consider using a plastic container rather than a net, as the fish can injure its fins and scales while thrashing around. This also increases stress! If a net is the only option, soak it prior to use. Dry nets are much more likely to cause injury than wet ones.
Allow the water temperature to change as the seasons change. While goldfish don't like temperatures over 75°F (24°C), they do seem to like seasonal variations where the temperature falls to the high 50s or 60s (15-20°c) in the winter. Fancier goldfish are an exception and cannot easily tolerate temperatures below about 60°F (16°c). Be aware that goldfish will not eat below 50-55°F (10-14°c).
Feed the goldfish one to three times daily with food specifically designed for goldfish. If you choose to feed them more often, then reduce the size of the meals so you don't overfeed. Give them only as much as they can eat in a few minutes, and clean any leftovers immediately. If a floating food is used, soak it in water for a few seconds before feeding so that it will sink. This reduces the amount of air the fish swallows while eating, which in turn reduces the risk of buoyancy problems.
Quote tags added. -ocalhoun