How to Install Linux Software on a Mac with MacPorts

MacPorts is a command-line package manager for macOS. If you’re familiar with apt-get or yum from Linux, then you know what a package manager does. It handles downloading, installing, updating and managing certain applications and their dependencies within macOS. With MacPorts you can install Linux applications on macOS from the command line.

Most of these applications are open-source, command-line utilities, but there are a fair share of “real” open-source, GUI-based applications. as well.

Like any package manager, MacPorts searches a library of downloadable software. When you find what you need, MacPorts downloads and installs the appropriate software and dependencies in the right place. This saves you the trouble of downloading repositories from GitHub and building software from source packages while still getting access to a wide range of Linux’s best command-line tools and GUI applications.

If you read our post on Homebrew, you know that macOS is missing some “standard” Linux terminal commands out of the box. Mac users won’t find common command-line tools like nmap or wget, and there’s no native package manager on the Mac to provide them. You can also use MacPorts to install open-source software like GIMP.

MacPorts requires the latest version of Xcode for your OS version. You can download Xcode from the Mac App Store or Apple’s developer website.

install-linux-apps-mac-macports-xcode

While you can run most of the MacPort commands without Xcode, you won’t be able to run many of the packages until you install it.

Installing Xcode Developer Tools

1. Open Terminal and use the command below to trigger the installation of macOS’ developer tools:

xcode-select --install

install-linux-apps-mac-macports-00001

2. Click “Install” in the pop-up box.

install-linux-apps-mac-macports-xcode-2

3. Wait for the files to download and install.

install-linux-apps-mac-macports-xcode-3

Installing the MacPorts Package

If you already have the Xcode and the developer tools installed, you can jump right to this step.

1. Download the latest release of MacPorts from GitHub. Make sure you scroll down to choose the version that matches your version of macOS. At the time of publication, there is no version of MacPorts for Apple’s newest OS, High Sierra.

install-linux-apps-mac-macports-install

2. Install the package from your Downloads folder.

3. Open a new Terminal window and run the command port.

install-linux-apps-mac-macports-00002

If that command returns “MacPorts 2.4.1” and provides a slightly different-looking command prompt, then you’re ready to rock!

To install some Linux apps on macOS with MacPorts, we will first need to search for the relevant programs.

1. To see a gigantic list of all available packages, open Terminal, type port list and press Enter.

install-linux-apps-mac-macports-00003

install-linux-apps-mac-macports-00004

3. Obviously, that’s a lot to look through. We can use the port search command to find something specific. Let’s search for nmap using the command below:

port search nmap

install-linux-apps-mac-macports-00005

4. That returns a few matching packages. The  first one, just called “nmap,” is the one we’re looking for.

install-linux-apps-mac-macports-00006

5. To get more information about that package we can use the info command:

port info nmap

install-linux-apps-mac-macports-00008

6. That returns some specific information about nmap. That all looks good, so we can install with the command below:

sudo port install nmap

install-linux-apps-mac-macports-00009

Note the sudo prefix which will require your admin password to fire.

7. Depending on the package you’re installing, there might be a large list of dependencies. These are software packages that your desired port relies on, and you’ll need to install them alongside your port of choice. Type “Y” and press “Enter” to accept the installation.

install-linux-apps-mac-macports-00010

8. When the installation is complete, you can run the command as you would on Linux via Terminal.

macports-run-linux-command

MacPorts is a powerful package manager that will connect you to a huge array of open-source binaries and applications that you can download and install on demand. If you want to learn more of the application’s commands, you can check out the MacPorts Guide for more information.

Leave a Reply

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.