How to Fix ‘sudo apt-get command not found’ on macOS

The “sudo apt-get command not found” error on macOS occurs because apt-get is a Linux package manager not available on macOS. This error indicates that macOS doesn’t recognize the apt-get command, as it uses different package managers like Homebrew or MacPorts. The error is often due to the mistaken belief that macOS uses apt-get by default.

Error Message

Additionally, misconfigured or missing $PATH environment variables can cause terminal commands to malfunction.

In this article, we will discuss different ways to solve this problem.

1. Install Homebrew on macOS

To potentially resolve the ‘sudo apt-get command not found’ error on macOS, you can try using Homebrew. This macOS package manager lets you install and manage software easily, like apt-get on Linux, by organizing packages in their own directory and symlinking files into /usr/local.

  1. Press Command + Space to open Spotlight, type Terminal, and press Enter.
    Opening Terminal
  2. Install the Xcode command-line tool with:
    xcode-select --install
    Installing the Xcode command-line tool
  3. To install Homebrew, run:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    Installing Homebrew
  4. During installation, press Return and enter your password for confirmation.
  5. You’ll receive a confirmation message upon successful installation:
    Successfully installed message
  6. Use Homebrew to install packages with:
    brew install name
    Installing the package using Homebrew command

    Note: Replace “name” with the package you want to install.

  7. The Brew command completes the package installation successfully.

2. Install MacPorts on MacOS

MacPorts is used for compiling, installing, and managing open-source software. It automatically installs any required dependencies for the software you’re trying to install. With MacPorts, you can easily install, download, or compile applications and libraries using a single command. It also provides options to upgrade and uninstall installed software.

  1. Open the App Store, search for Xcode, and click Get to install it. You will need to enter your username and password.
    Installing Xcode from the App Store
  2. Open Xcode and click Agree to the license agreement, or use the command in Terminal:
    sudo xcodebuild -license
    Agree button for the agreement
  3. Open Terminal by pressing Command + Space, typing Terminal, and pressing Enter.
    Opening Terminal
  4. Install the Xcode command-line tool with:
    xcode-select --install
    Installing the Xcode command-line tool
  5. Download MacPorts from this link.
    Downloading MacPorts from the site
  6. Open the downloaded file and follow installation prompts, entering your password if needed.
  7. After installation, restart Terminal and update MacPorts with:
    sudo port selfupdate
    Updating and checking MacPorts in Terminal

    Note: Successful installation shows ‘Updating MacPorts base sources using rsync‘. Reinstall if not seen.

  8. To install a package, use:
    sudo port install name
    Installing through MacPorts

    Note: Replace “name” with the package name you wish to install.

ABOUT THE AUTHOR

Kevin Arrows


Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.