Taking better care of your tech gear can help make it last longer, but sometimes you just need to upgrade. Even if your phone, tablet or computer hasn’t suffered a fatal flop, you may find it doesn’t fit your work-from-home needs, or you plan to pass it down to a family member who needs it for remote learning. Or, be honest: You really want the fall season’s latest, greatest phone.

Whatever the reason for the new purchase, simply tossing your old hardware in the junk drawer or trash can be bad from a privacy standpoint and for the environment. When upgrade time comes, here are some security and eco-friendly tips for when your old equipment goes on without you.

To get your old device ready to leave your possession, start by backing up its contents to an external drive or secure cloud server.

Next, look for a program to automatically move your data from the backup or old device. Apple’s support site has guides for transferring the contents of Mac computers and iOS gadgets, along with advice for giving away a Mac or one of Apple’s phones or tablets.

Now, de-authorize your old device from any online subscriptions for music, movies, software and cloud services. Make sure you have any serial numbers or installation programs needed to reinstall applications on new hardware. (Unless you installed an application from a disc or drive and have the paperwork, serial numbers are typically emailed when you buy computer software online and are still needed even if you download the program again on a new machine.)

Finally, unpair any Bluetooth accessories before you sign out of your user accounts on the device for good.

After you’ve transferred your data to its new home, wipe the information from the old device. On an iPhone or iPad, go from Settings to General and then Reset; select the Erase All Content and Settings option. Wiping an Android phone varies by hardware and software versions, but try going to System, then Advanced and Reset Options.

Computers should also be wiped of data before they leave the house. Apple’s support site has guides to erasing a Mac and reinstalling its operating system. PC users have several disk-deleting programs available, including White Canyon’s WipeDrive Home and Eraser. Check with the computer’s manufacturer for steps to reinstalling the operating system; using another PC with an external drive to download and reinstall Windows 10 or Ubuntu Linux may be one method.

The recipient of your used computer or mobile gadget will need to set it up and install any new applications. If you plan to give your old smartphone to someone in the family, check with your wireless carrier about adding a new line and other necessary equipment (like a SIM card) to get it up and running.

Even without cellular service, Wi-Fi-enabled phones and tablets can still get online by connecting to a wireless network. And if you’re bequeathing a phone or tablet to a child, Apple and Google both include parental controls in their software.

If money is tight, swapping your old gadget for credit helps pay for the new one. Several hardware manufacturers — Amazon, Apple, Dell, Google, Samsung and others — have their own trade-in programs.

Some manufacturers support “takeback” programs that accept products mailed in for recycling; Amazon, Apple and Google are among them. Best Buy and Staples stores also accept all kinds of electronics for recycling. If pandemic precautions are temporarily impeding collection, set a reminder on your new device to check back.