Tips for increasing the longevity of your Mac If you have a new or used Mac then you likely would like to ensure it stays working for as long as possible.

Regardless of whether you purchase it new, refurbished, or used, your Mac is likely a sizable investment that you might wish to keep running for as long as possible, not only because of the cost factor but also because of the time and effort it would take to migrate your data and workflow to a new system (even though Apple has made the latter quite easy if you have proper backups).
There are many ways your Mac can get damaged, become outdated, or otherwise experience greater wear and tear from use that can shorten its lifespan. In most cases these will only have a little (if any) effect on the system but may help keep the system running longer and without problems or capacity limitations.

The physical

The first part of your Mac is the physical machine, which includes the logic boards and controllers, screen, keyboard, mouse, and other similar components. While peripherals like the keyboard and mouse can be replaced, it may be harder to do so for the components in the machine.
The machine itself
Of the considerations for ensuring a long-lasting Mac, the first begins before you even purchase it where you are offered options to configure your system. Apple offers a number of configure-to-order details including RAM capacity, processor speeds and types, and hard-drive size.

Apple RAM offerings
Apple periodically updates its maximum RAM offerings.


 
While for the most part these should be relatively comparable, the faster you go and the more capacity you give the system the longer you will be able to use it before you need to upgrade. For RAM considerations I've usually recommended people get the minimal from Apple and then upgrade at a later date to save money; however, for some of Apple's systems such as the MacBook Air and Retina MacBook Pro this is not possible, so purchasing the ones with the most built-in RAM is recommended.
These same recommendations extend to hard drives and processors, especially for systems like the iMac that cannot be easily serviced (if at all in some cases). If you are offered the option to get a Core i5 versus a Core i7 processor for your system, then if you can afford it I would recommend the upgrade (which sometimes comes with the benefit of a faster graphics processor as well). Likewise, consider an SSD over Apple's Fusion Drive, and a Fusion Drive over a conventional hard drive for increased speed.

For hard drives, capacity is not so much an issue as you can always use an external storage device if needed, but the speed of your internal drive that holds your OS and applications is one of the biggest data bottlenecks in the whole system so buying the fastest one will keep your system running in top gear.
Power source care
Of the remaining details, perhaps one of the more common items to be damaged is the system's power supply, which being subject to relatively harsh and noisy wall power circuits can potentially break down over time. In addition, the external power supply for laptops may experience a greater degree of physical abuse that can eventually lead to a failure.
Apple power adapter
Apple's power adapters may be subject to wear with use, or be replaced with newer options.


 
For power supplies, continued use is not too much of an issue, but surges and sudden power failures may disrupt the system and result in data corruption or broken components (hard drives or the power supply itself), so be sure to help protect your system by either turning it off when not in use, at least using a surge protected power strip, or better yet use a Uninterrupable Power Supply (UPS).
For laptop users, consider purchasing a second power supply for your system, especially since as new technologies become available the older ones may be phased out. For example, Apple recently released new Lightning connectors for iOS devices and a new MagSafe connection for its laptops. While the older MagSafe connections should be available for a while, over time they will be harder to find.

In addition to the power supply for laptops, be sure to take proper care of its batteries. For the health of the batteries, the best practice is to use them regularly (often enough to run through a full charge cycle about once per month) to help prevent dead spots that can reduce their overall capacity. Additionally, do not use them in extreme temperatures, and if you store system for a long period of time, be sure to charge the battery until it is half-full before doing so.
Battery calibration is not a necessary step for its health; however, it can be done regularly as a way to ensure the battery is regularly used.
Avoid abuse
While it might be needless to say, avoiding physical abuse of the systems is another easy way to increase the longevity of Apple's systems. The aluminum Apple uses in its systems is durable and quite protective, but is not indestructible. If you travel with your system then consider using a case or cover that will help protect it, and also consider using a properly padded bag even if you use a case.
In addition to transport security, consider a keyboard slip cover for laptops to help protect the keys from wear. The keys on a MacBook keyboard have a slightly matte finish to them out the factory door, but over time with you pressing them the keys will become shiny as you wear down the top surface. In some cases the wear can be great enough so the symbol disappears making it difficult to type. One option instead of a slip cover is to get a set of transparent stickers to place on the keys that are showing any wear.
Lastly, be kind to the ports on your Mac. When peripherals are attached, the ports can be subject to torquing that in extreme conditions or over time may result in it no longer working, not being able to hold the inserted connection firmly, becoming mangled, or even being subject to shorting out and frying a component of the motherboard. This is easily done by inserting the incorrect plug into a port, so avoid fishing around blindly to insert a connection by feel.
Be aware of your touch
I've often noticed people hammering on keys when typing, or mashing a key or two in frustration, and while the keyboard ought to be able to take such treatment, it can only lead to faster wear. If your system is not working properly then clicking or tapping harder or faster will not fix the situation, and will only increase the chance of damaging the system. In some cases multiple presses during a frustrating hangup can even confuse the system more and make the matter worse.
In addition to using a gentle touch on the keyboard, avoid touching your display, especially if you have one with a matte finish. Apple's glossy glass displays are decently protected from touching, but matte displays can easily be poked and damaged.
Ensuring you have clean hands when using your system is another way to help increase its longevity. Grime and oils on hands can help wear down the surface of keys or simply contribute to dirt that gets into the keyboard and can potentially block a key or two from working.
Clean your system
Dirt and grime on a system will not necessarily hurt it, but over time it can become unsightly and may build up enough to cause a problem or two, so be sure to gently wipe away any grime in keyboards or around the edges of your display, but more importantly be sure the ports and vents are clear of dust or obstructions. It is very easy for dirt to get into these ports, and if you press a connection into them then you only jam the dust in farther, so be sure to check your data ports and clean them out.
For the vents on the system, use canned air or a vacuum cleaner to remove any dust that you see in them, as any reduction in the efficiency of these vents may lead to a system that more easily overheats. For Mac Pro systems, you can easily remove the cover and use canned air to blow around the fans and heat sinks to clear any dust accumulation (do this outside, as billowing clouds of dust can be irritating to live with).
Avoid hard shutoffs
Finally, unless your system is experiencing a crash or severe hangup, then avoid holding the power key to shut it off or unplugging it as this sudden interruption can be damaging to the system's logic boards and components. If you are finding the system is regularly crashing then try addressing this problem instead of resorting to always shutting your system down by yanking the plug or pressing the power key. There are numerous resources for helping find the source of hangs and crashes in OS X, including Apple's retail stores and its online discussion forum.

The logical

Besides taking care of your system's physical condition, consider lengthening its usefulness by maintaining its capabilities, security, and stability. Doing this not only involves the operating system and software that you use, but also considers any components and upgrades that are available for your system.
Software Update
Software Update is available in the Apple menu.
 
Upgrade software
While it can be argued that the features and details in the latest release of OS X may not suit your needs, at least be sure to update your current OS installation to its latest version, as this will ensure the best security and fixes to problems that people have been experiencing. Updating a system can easily be done by going to the Apple menu and choosing Software Update, where the system will check for and then install new versions of operating system software or Apple's supplied programs like iTunes, iPhoto, or iWork.
In addition to Apple's software, be sure to update any third-party software you have installed and keep those at their latest versions, not only to help maintain security but also to ensure compatibility with OS X. Most programs offer built-in updating features similar to Apple's software-update, and can be configured to check for updates on launch or on a regular schedule, so consider setting these up along with doing so for Apple's Software Update to ensure you are running the latest versions of all of your software.
Upgrade hardware
As you use your system and install new releases of OS X and upgrades to your software, you may find that the new software demands more out of your system and can result in a slower system. Therefore, as mentioned above for new systems consider the faster upgrades at purchase, but for older and used systems you can still consider similar upgrades to breathe new life into it and get you up and running faster without needing to purchase a new computer.
The two most common options are to upgrade your system's RAM capacity to give your processor and applications adequate "desk space" in which to perform computations. While 8GB to 16GB of RAM should be adequate these days for most uses, in general the more RAM the better so get as much as you can afford. Just be sure to fully test your RAM once you have installed it to ensure it is working correctly, as bad RAM can be a major source of crashes and data corruption.

OWC Data Doubler

Other World Computing's Data Doubler offers a convenient way to put two drives in an older MacBook system.
   
Also consider a faster storage medium such as an SSD in place of a conventional hard drive. For laptop systems you can replace older and unused optical drives with a secondary internal drive, giving yourself the options for increased capacity, dual-drive redundancy, an internal backup, options for implementing Apple's "Fusion" drive, and more.
To give a rough estimate, an 8GB RAM upgrade, a 240GB SSD, and an optical drive conversion kit for an old 2008 MacBook Pro will cost about $300 to $400 and will at times more than double the speed of your old system.
Finally, for Mac Pro systems you can upgrade the graphics card for increased graphics performance. While the offerings for this are relatively limited and a touch expensive, if needed the option to do so is out there.
Take care of slowdowns and other problems
Over time and depending on how it's used a Mac can develop odd problems or two that can lead to slowdowns, crashes, hangs, and other odd behaviors that can be a real burden to deal with. Sometimes the issues can be quite difficult to track down, but in general if you are experiencing odd problems there are some approaches you can quickly take to clear them up or at least help identify where the root of the problem may be.
To do this, first try running a general maintenance routine on your system to clear caches and other temporary items that if corrupted may lead to odd problems. Additionally, you can run through a general troubleshooting routine to help identify if the problem is systemwide, because of a third-party program or two, or rooted in your user account, which can greatly help if you need to communicate the problem to others for help.
Lastly, Apple's hardware test suite should be available to most Mac systems and can be used to test the system's RAM and internal sensors to see if a problem is occurring.
Time Machine preferences
Time Machine offers options to back up to more than one drive.
Back up regularly
A final consideration for increasing your Mac's longevity is to make continual backups. Your Mac's hardware is only half of the story, and your Mac experience lies mainly in your documents, settings, installed applications, and the entirety of your system's software environment. With proper backups, should an irrecoverable problem happen to your system then you can easily restore or migrate your data from the backup to a new system and be up and running as if nothing ever happened (minus the cash for a new system, of course).