Installing Additional Programs with a Package Manager

Learn how to install additional packages using the CLI.

Package manager

The operating system has a bunch of programs already installed, but we want to install more. We might be used to going to an app store or downloading some files from a website and installing them. Still, POSIX (Portable Operating System Interface) systems traditionally offer package managers to make downloading and installing software easy. Each operating system has its own package manager. Debian and Ubuntu use the apt package manager, while Fedora and CentOS use yum.

If we’re using Bash on Windows, we use apt because the Bash environment is based on Ubuntu.

Installing packages on macOS

If we’re on macOS, we don’t have a package manager installed. We can install the package manager Homebrew2 by following the directions on its official homepage.

And for macOS with Homebrew, we use this command:

$ brew update

However, Homebrew updates its packages automatically before installing a package. Also, notice that we don’t need the sudo command with Homebrew. Homebrew installs programs into a directory within the /usr/local directory. During the Homebrew installation process, it modifies the permissions on that directory, so the user has access to modify its contents.

We install a few programs throughout this course using package managers, so let’s make sure everything works.

Using yum and apt to install packages

Whenever you use the package manager to install a program, make sure you have the latest list of packages. The package manager will have a command that fetches that list for you. If you’re using apt, you’ll use this command:

$ sudo apt update

If we’re using yum, the command is similar:

$ sudo yum update

Installing the tree package

Let’s install the tree package, which lets us visualize a directory structure. We’ll use it in the next chapter. For systems using apt, install it with the following command:

$ sudo apt install tree

If using yum, install tree with this command:

$ sudo yum install tree

And for macOS with Homebrew, use this command:

$ brew install tree

The package manager will install the program. It may ask us to confirm the installation, which we should accept. Once the package is installed, we can use the tree command. Try it out.

$ tree --version

We’ll use the tree command throughout this course to visualize directory structures. Run this terminal to check the tree version and run some of the Linux commands. Avoid using yum here.

Get hands-on with 1200+ tech skills courses.