We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

Linux Package Managers: apt, brew, and How They Work

Boot.dev Team
Boot.dev TeamProgramming course authors and video producers

Last published

Table of Contents

A package manager is a software tool that helps you install other software. As a developer, you'll frequently use package managers to get access to the software you need to get your work done. In this post we'll cover the two most popular package managers you'll run into on Linux and macOS — apt and brew — how they work under the hood, and how to use them to install real tools like Neovim and VS Code.

All the content from our Boot.dev courses are available for free here on the blog. This one is the "Editors and Packages" chapter of Learn Linux. If you want to try the far more immersive version of the course, do check it out!

What Is a Package Manager?

A package manager's primary functions include:

  • Downloading software from official sources
  • Installing software
  • Updating software
  • Removing software
  • Managing dependencies

That last one is a big deal. Most software depends on other software to run, and manually hunting down every dependency (and every dependency's dependency) is miserable. A package manager does it for you.

Apt and Brew aren't the only package managers out there. There are many, many more, though they do happen to be two of the most popular, especially on Linux and macOS.

APT: The Default on Ubuntu

APT, or "Advanced Package Tool," is the primary package manager for Ubuntu. To be fair, you can use other package managers on Ubuntu, but APT is the default and most common.

If you're on WSL and Ubuntu, you'll be using APT. If you're on another Linux setup, I pray you already know what package manager you're using. You can check that you have APT installed by running:

apt --version

Before installing anything, make sure apt itself has an up-to-date list of available packages:

sudo apt update

This command only updates apt's package lists; it doesn't upgrade any of your installed software. (That's what sudo apt upgrade does.) Notice the sudo — installing software system-wide requires root privileges.

Then install something, like Neovim:

sudo apt install neovim

Brew: The (Unofficial) Standard on macOS

There isn't a "default" package manager for macOS. The most popular (but unofficial) package manager is Homebrew.

If you're on macOS and you don't have Homebrew installed, you can install it by running the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once you have it, installing software feels a lot like apt:

brew install neovim

How Do Package Managers Work?

When you type a command like apt install neovim, the package manager will:

  1. Check to see if the package is already installed.
  2. If it's not installed, it will download the package from a repository.
  3. It will install the package on your computer.
  4. It will install any dependencies that the package needs to run.
  5. It will (hopefully) add the package to your PATH if it should be there.

Good package managers keep track of what packages you have installed, and what versions of those packages you have installed. They keep your filesystem nice and tidy, making sure you haven't installed 10 different instances of the same package or application.

If you're curious where your package manager put something, the which command will tell you:

which nvim
# /usr/bin/nvim

Using Neovim (and Escaping It)

So why did we install Neovim? Neovim is a hyperextensible (and newer) version of Vim, which is a "new" version of Vi, which is a popular command line text editor. This isn't a course on Neovim (we'd need at least 420 more lessons for that), but let's at least figure out how to edit a file and exit the program.

Don't be fooled, exiting Vim (or Neovim) is one of the greatest hurdles you must overcome as a developer. It's a rite of passage. It's a badge of honor.

You can open a file with Neovim by passing in the file path as an argument:

nvim notes.md

Once it's open, you might notice that you can't type anything. That's because you're in "normal" mode, the mode for navigating and manipulating text. Here's the minimal survival guide:

  • Move around with the arrow keys (I know, Vim sacrilege)
  • Press i to enter "insert" mode — you'll see -- INSERT -- at the bottom of the screen, and now you can actually type
  • Press Esc to return to normal mode
  • Type :w and press Enter to save your changes
  • Type :q and press Enter to quit

That's it. You've successfully edited a file (and escaped from) Neovim.

Webi: Installing Tools Without a Package Manager

There is one more package manager (actually more of an anti-package manager) worth knowing about: Webi.

Webi lets you install command line tools directly from the web, with no need for a traditional package manager like apt or brew. You don't need to install Webi itself at all; instead, you just run a shell command that downloads and runs a given tool's official installer script.

For example, here's how you'd install lsd, a more modern version of the ls command:

curl -sS https://webi.sh/lsd | sh

One of the coolest features of lsd is that you can view your files in a tree-like structure:

lsd --tree --classic transactions
# ├── file.csv
# ├── another-file.csv
# └── a-folder
#     └── last-file.csv

Is It Safe to Pipe a Script Into Your Shell?

As a general rule, it's not smart to pipe a shell script from the internet directly into your terminal, because that script could do malicious things. That said, as long as you're doing it via HTTPS and you trust the source (in this case webinstall.dev), it's not as big of a concern.

If you want to hear more about this, here's the section of the Backend Banter podcast episode where Webi's creator talks about it in more detail.

Terminal Editors vs GUI Editors

Some developers do all their work inside a terminal and use a terminal editor like Neovim, but a lot of developers, myself included, prefer a hybrid GUI/terminal experience.

Enter VS Code. It's a fairly lightweight editor that's easy to use for beginners, but powerful enough for professionals. VS Code (not to be confused with Visual Studio) is the most popular code editor among developers today.

Some other cool GUI editors include:

And some of the most popular terminal editors are:

If you don't already have a preferred editor, install VS Code — it's the safe default choice.

How Do You Use VS Code With WSL?

If you're on Mac or Linux (non-WSL), you can skip this part. However, if you're on WSL, you need to set up VS Code to work with WSL. This will allow you to use the full power of your Linux filesystem within VS Code:

  1. Open VS Code and navigate to the "Extensions" menu on the left-hand toolbar.
  2. Search for "WSL" and install the extension created by Microsoft.
  3. In the very bottom-left corner of VS Code, there should be a >< remote button. Click on that and select "Connect to WSL using Distro" and select "Ubuntu."

You should now have a new WSL-ready VS Code editor. I recommend pinning this window to your taskbar so that you can always open the WSL-enabled version of VS Code in one click. You won't have access to your Linux filesystem if you're in the "regular" VS Code window, so I'd just avoid it completely.

With a package manager and a real editor set up, you've got a legitimate local development environment. If you want to put it to work, the Learn Linux course walks you through all of this hands-on, and Learn Git is the natural next tool to install with your shiny new package manager.

Frequently Asked Questions

What is the difference between sudo apt update and sudo apt upgrade?

sudo apt update refreshes apt's list of available packages and versions, but doesn't install anything. sudo apt upgrade actually installs the newer versions of the packages you already have. You typically run update first, then upgrade.

What package manager does Ubuntu use?

Ubuntu uses APT (Advanced Package Tool) by default. You can use other package managers on Ubuntu, but APT is the default and most common, and it's what you'll use on WSL with Ubuntu.

Is it safe to pipe a curl script directly into your shell?

As a general rule it's risky, because the script could do malicious things. That said, if you're downloading over HTTPS from a source you trust, like brew.sh or webinstall.dev, it's not as big of a concern.

How do I exit Vim or Neovim?

Press Esc to make sure you're in normal mode, then type :q and press Enter to quit. Use :wq to save and quit, or :q! to quit without saving your changes.

Related Articles