Installing Tools: Homebrew and apt
A package manager is an app store you type to; on Ubuntu it's apt, which needs sudo to install, and on a Mac it's Homebrew's brew, which doesn't, and both search, install, update and remove tools by name.
Apprentice · Unix · Linux · Updated
After this lesson you can
- Find a tool's package and check whether it's installed with apt search and apt-cache policy, or brew search and brew info
- Install, update and remove tools with sudo apt or with brew, and tell apt update from apt upgrade
Key takeaways
- A package manager installs programs by name from a catalog its makers check. Ubuntu and WSL use apt; a Mac uses Homebrew, typed brew.
- apt search and apt-cache policy look things up and change nothing. brew search and brew info do the same on a Mac.
- sudo apt install name installs a tool, and sudo apt remove name removes it. On a Mac it's brew install and brew uninstall, never with sudo.
- apt update only refreshes the catalog. apt upgrade installs the newer versions. Run them in that order; brew update and brew upgrade work the same way.
A tutorial says "run tree to see the project's folders", and your terminal says this:
tree
Command 'tree' not found, but can be installed with:
sudo snap install tree # version 2.1.3+pkg-5852, or
sudo apt install tree # version 2.3.1-1
See 'snap info tree' for additional versions.
The program isn't on your computer yet. You could search the web for it, find a download page, and hope it's the real one. Or you can ask your computer's package manager: an app store you type to. Developers get nearly every tool this way, and IT administrators set up whole servers with it, one line per program.
An app store you type to
A phone's app store has a catalog, installs an app by name, keeps every app up to date, and removes one cleanly. A package manager does the same for the terminal. Each program comes as a package, and the catalog lists thousands of them, checked by the people who look after the store.
- Ubuntu, and Ubuntu in WSL on Windows, use apt. In WSL, apt installs into Ubuntu, not into Windows.
- A Mac uses Homebrew, typed
brew, which Setup: The Terminal on a Mac installed.
The tree message above offers a second store, snap, which Ubuntu also has. This course uses apt.
Look before you install
Searching changes nothing, so it needs no password. apt search looks through the catalog's names and descriptions. A short word like jq matches hundreds of descriptions, so --names-only with '^jq