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

Most Debian uses dpkg packaging system which provides programs and applications for installation. Because of this packaging system, users don’t need to build programs from the source codes. The tool required to interact with this packaging system is APT (Advanced Package Tool). However, sometimes, this APT tool will not work on macOS and give an error “sudo: apt-get: command not found“.

Error Message

What Causes the ‘sudo apt-get command not found’ Error on macOS?

Whenever there is an error ‘command not found’ on your Terminal, it means that the command you are trying to use for specific application or library is not available. If the application or utility is not installed on your system then all the commands or functions related to that utility will not work. We all know that the commands on Terminal of Linux and macOS are 99% same. However, it doesn’t mean both Linux and macOS will be using the same managers and utilities for installing and managing the packages. In conclusion, the APT commands are not available for macOS.

Alternatives of APT for macOS

APT commands are used for download, updating or upgrading applications through Terminal. However, this option is only for a few Debian Linux distributors. So macOS have few alternatives which work the same as the APT. These alternatives are used for the same work of APT and come with a few different/better features.

Method 1: Installing Homebrew in macOS

The command ‘apt-get‘ is intended for installing packages on Linux systems. Homebrew is the equivalent for the Mac. It is the package manager that most people feel comfortable with using it. Homebrew installs packages to their own directory and then symbolic links their files into /user/local. You can install homebrew and run command to install packages by following the steps below:

  1. Hold Command key and Press Space to open Spotlight, then type Terminal and Enter.
    Opening Terminal
  2. First, you need to install the Xcode command-line tool by using the following command:
    xcode-select --install
    Installing the xcode command-line tool
  3. After the Xcode tool installation, now type/copy the following command to install Homebrew on macOS:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    Installing homebrew
  4. The installation will ask for Return (Enter) key and password for confirmation.
  5. You will get the installation successful message for correctly installing the tool as shown below:
    Successfully installed message
  6. Now using Homebrew, type the following command to install any package you want to install:
    brew install name
    Installing the package using homebrew command

    Note: Name in command can be the package name that you are trying to install on your macOS.

  7. Brew command will successfully install the package on your system.

Method 2: Installing MacPorts in macOS

MacPorts software is used for compiling, installing, and managing open source software. MacPorts will automatically install any required dependencies for the given port that the user is trying to install. It is easy to use; you can install, download or compile an application and library by using a single command. MacPorts also provides upgrades and uninstalls for the installed ports. You can install it by following the below steps carefully:

  1. Open App Store from Dock and search for Xcode in the search box. Click on Get and install the Xcode. Be Patient this will take some time to install because the size is around 6GB.
    Note: It will ask for username and password for the account you are using on App Store.

    Installing Xcode from the App Store
  2. You can agree to the agreement of Xcode by opening the application from App Store or Dock and clicking the Agree button.
    The Agree button for the agreement

    Or by typing the following command in Terminal to agree with the agreements.

    sudo xcodebuild -license
  3. Hold Command key and Press Space to open Spotlight, then type Terminal and
    Opening Terminal
  4. Type the following command to install the Xcode command-line tool:
    xcode-select --install
    Installing the xcode command-line tool
  5. Now download MacPorts for your Operating system that you are using from here: MacPorts
    Downloading MacPorts from site
  6. After downloading, open the downloaded file and install the software by going through the installation process/steps and providing the password if asked.
  7. Once the installation is complete, restart Terminal and type the following command:
    sudo port selfupdate
    Updating and checking MacPorts in Terminal

    Note: MacPorts is successfully installed if you see the message ‘Updating MacPorts base sources using rsync‘. However, if you don’t see this message, then you need to reinstall it correctly again.

  8. Now you can install any package by using the following command:
    sudo port install name
    Installing through MacPorts

    Note: Name in command can be the package name that you are trying to install on your macOS.

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.