macOS protects you from malicious software with Gatekeeper, which checks that apps come from the App Store or an identified developer and have been notarised by Apple. This guide shows the normal ways to install apps and what to do when macOS blocks one.
1The App Store
The Mac App Store is the simplest and safest source: apps are reviewed, sandboxed and updated automatically. Open App Store, search, and click Get or the price. Updates appear under Updates, and you can turn on automatic updates in the App Store settings (Command+,).
2Apps from the web
Download only from the developer's own site. Most apps come as a .dmg disk image: open it and drag the app into the Applications folder, then eject the disk image. Some come as a .pkg installer, which walks you through the steps and may ask for your password. Read what it is about to install before you agree.
Run apps from /Applications, not from the disk image or Downloads. Apps run from a disk image can't update themselves.
3When Gatekeeper blocks an app
The first time you open a downloaded app, macOS asks you to confirm. If it says the app can't be opened because Apple can't check it for malicious software, don't simply override it. First make sure it came from a source you trust.
If you trust it, open System Settings > Privacy & Security, scroll to the Security section, and click Open Anyway next to the message about the app. Confirm with your password or Touch ID. This button appears for about an hour after you tried to open the app. (On current macOS, Control-clicking the app and choosing Open no longer bypasses this check.)
4Check Gatekeeper from Terminal
spctl --status
# assessments enabled = Gatekeeper is on
spctl --assess --verbose /Applications/Example.app
You may see advice online to remove the quarantine attribute with xattr or disable Gatekeeper entirely. Avoid it: it removes protection for every app, not just the one you want.
5Removing apps
For most apps, drag the app from Applications to the Bin. Apps that came with an uninstaller, or that installed with a .pkg, should be removed with the developer's uninstaller. App Store apps can also be deleted from the Applications folder.