Fix ‘sudo apt-get command not found’ on Mac

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

Advanced Packaging Tool, or APT, is a command-line used to install or remove software on Debian, Ubuntu, and related Linux distributions. Ubuntu is based on Debian Linux, which uses a dpkg packaging system that provides applications and installation programs. The command line APT interacts with the dpkg packaging system and makes managing software easy and efficient. It automates the retrieval, configuration, installation of software packages, and more.

The command 'sudo apt-get' is used for installing, upgrading, or removing software packages. While executing this command in the Terminal window of your Mac, you have probably encountered the line 'sudo apt-get command not found.' That means that the command you're trying to use is not available. In other words, the command 'apt-get' is not accessible on macOS, as it's only specific to some varieties of Linux. Fortunately, macOS has a few alternatives that work the same as the APT. You can choose between Homebrew and MacPorts.

How to fix 'sudo apt-get command not found' on your mac

Homebrew is a free package management system that creates executables and installs them into a predictable location for your Mac to execute later. It installs the right software packages that let you compile and run various apps and software on your Mac. As their site states, "Homebrew installs the stuff you need that Apple didn't". The program installs packages to their directory and symlinks files into /user/local. If you're familiar with the command lines, you can either edit the Homebrew formula as you need it or create a new one. You can also install your own stuff. Homebrew was released in 2009 and lives on user donations. The program also collects installation, build error, and operating system version statistics via Google Analytics. You can view analytics data up to 365 days on the Homebrew website. If you're not comfortable with Homebrew collecting information, you can opt-out from it by using the command brew analytics off.

MacPorts, formerly known as DarwinPorts, is a package management system for compiling, installing, and upgrading command-line, X11 or Aqua based open-source software on your Macs operating system. This package management system was released in 2002 as part of the OpenDarwin project. The MacPorts repository is full of open source applications found on Linux or related operating systems. There are over 21,600 ports as of August 2019. If you were a Linux user, there is a good chance that you'll be able to find your favorite apps by using the "port search" function.

The difference between both systems is that Homebrew does not require 'sudo' to modify the system-wide software directory, while MacPorts do. Command 'sudo' allows you to run programs with the security privileges as the superuser. It will ask for your user password and will confirm your request to execute a command. Suppose you prefer not to use the command 'sudo' when installing packages. In that case, it's recommended not to use a system-wide directory as it won't protect your computer from being used as a tool for exploitation. The right to install, remove, or change any software should only be available for a user with root privileges as a safety measurement.

Both systems are a great choice. Choose which one you want to use and proceed to the steps below for installation and usage guide.

Table of Contents:

Install Homebrew

As it was mention above, Homebrew doesn't use sudo. Instead, they use a macOS sandbox that limits the damage done by a hijacked app. Each application gets its area, a "sandbox." For the app to go out of the sandbox, it needs to ask for permission from the operating system. The OS will either approve or deny the apps request depending on the sandbox settings and provide the least specific information possible to complete the request. Sandbox won't prevent attacks against your application, but it will minimize the damage.

How to install Homebrew:

1. Press the Command and the Space key on your keyboard to open Spotlight.
2. Type in "App Store" and press Enter to open it.

Open app store

3. In the App Store, search for Xcode.
4. Click on "Get" and install the Xcode. The installation will take some time because it is around 11GB.

Search Xcode in the App Store

5. After the download is complete, click on "Open" and agree to the License Agreement.
6. Follow the installation process.

Agree to Xcode License Agreement

7. After Xcode has been installed, press the Command and the Space key on your keyboard to open Spotlight.
8. Type in "Terminal" and press Enter to open it.
9. To install Homebrew on your Mac in the Terminal window enter the command line: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
10. You’ll be asked to enter your Mac passwords. The password is not shown in the terminal window.

Install Homebrew

11. The installation will ask you to press the Return (Enter) button to continue the installation.

Press Enter to confirm the installation of Homebrew

11. After the installation is done, you'll get the 'installation successful' message in the Terminal window.

Homebrew installed successful

To use Homebrew and install any package you want, enter brew and your install name like this: brew install name

Use command brew install name to install packages

The brew command will then install the package on your macOS.

[Back to Table of Contents]

Install MacPorts

MacPorts is a great way to compile, install, and manage open-source software. Before installing any program with MacPorts, you need to use the command 'sudo'. Without it, you won't be able to manage your applications, as you will need to confirm that you're the superuser of the system.

How to install MacPorts:

1. Press the Command and the Space key on your keyboard to open Spotlight.
2. Type in "App Store" and press Enter to open it.

Open App Store

3. In the App Store, search for Xcode.
4. Click on "Get" and install the Xcode.  The installation will take some time because it is around 11GB.

Find Xcode in the App Store

5. After the download is complete, click on "Open" and agree to the License Agreement.
6. Follow the installation process.

Agree to Xcode License Agreement

7. Download MacPorts for your operating system on their website.
8. Open the download file and install the software by following the installation steps.

Install MacPorts

9. When the installation is complete, press the Command and the Space key on your keyboard to open Spotlight.
10. Type in "Terminal" and press Enter to open it.
11. In the Terminal window, enter in the following command: sudo port selfupdate
12. Enter your Mac password. The password is not shown in the terminal window.

Execute sudo port selfupdate

If you see the message 'Updating MacPorts base source using rsync', it means that MacPorts was successfully installed. If you don't see this message, it means you installed it incorrectly.
To install a package, you need to use the command sudo port and insert the install name: sudo port install name.

Macports installed successfully

The install name can be the package name that you want to install.

[Back to Table of Contents]

Video on How to Fix ‘sudo apt-get command not found’ on Your Mac

[Back to Top]

About the author:

Tomas Meskauskas

I am passionate about computer security and technology. I have an experience of 10 years working in various companies related to computer technical issue solving and Internet security. I have been working as an editor for pcrisk.com since 2010. Follow me on Twitter to stay informed about the latest tech news or online security threats. Contact Tomas Meskauskas.

Our guides are free. However, if you want to support us you can send us a donation.