≡ Menu

9 Mac OS X Port Command Examples to Install and Update Packages

Port is a terminal command utility which is used to update open source software on Mac OS X.

The port command is bundled as part of MacPorts Framework.

You can install port command either by downloading and installing the binary version for your corresponding Mac OS X, or by downloading the source code and compiling it on your OS X version.

The binary file of MacPorts for various version of OSX are available here. Once you download the binary version, just click on the package to install it. You should have administrator right on your system to install it. X-code is pre-req for MacPorts. If you don’t have X-code on your system, it will display a warning message.

1. Update Port List using selfupdate

Immediately after you install the port command, you should update the available port list by doing a selfupdate as shown below.

$ sudo port -d selfupdate
—> Updating MacPorts base sources using rsyncbase.tar
MacPorts base version 2.2.1 installed,
DEBUG: Rebuilding and reinstalling MacPorts if needed
MacPorts base version 2.2.1 downloaded.
—> Updating the ports tree
Synchronizing local ports tree from 
The ports tree has been updated.

If you are behind the proxy, you need to add the following lines to /etc/sudoers file as sudoer before you perform selfupdate:

Defaults env keep += "ALL PROXY NO PROXY"

Add the following lines to your .bashrc at your home folder to get port connect from behind a proxy:

export RSYNC PROXY='username:password@proxyhostname:port number'
export HTTP PROXY='http://username:password@proxyhostname:port number'
export HTTPS PROXY='https://username:password@proxyhostname:port number'
export FTP PROXY='ftp://username:password@proxyhostname:port number'

2. Upgrade All Outdated Packages

After selfupdate it will ask you to do port upgrade for all outdated installed ports. You can upgrade all outdated packages using “upgrade outdated” option as shown below.

$ sudo port upgrade outdated
—> Computing dependencies for openssl
—> Fetching archive for openssl
—> Attempting to fetch openssl-1.0.1f 0.darwin 13.x86 64.tbz2 
     from http://mse.uk.packages.macports
—> Attempting to fetch openssl-1.0.1f 0.darwin 13.x86 64.tbz2.rmd160 
     from http://mse.uk.packages.m
—> Installing openssl @1.0.1f 0
—> Cleaning openssl
—> Computing dependencies for openssl
—> Deactivating openssl @1.0.1e 1
—> Cleaning openssl
—> Activating openssl @1.0.1f 0
—> Cleaning openssl

3. Search for a Specific Package

You can search for a specific package by using a keyword. This will search for all available packages with the given keyword, and display the corresponding version number of the available packages also.

The following will search and list all packages that contains the keyword “tmux” either in package name or description as shown below.

$ port search tmux
rainbarf @1.1 (sysutils) CPU/RAM/battery stats chart bar for tmux (and GNU screen)
tmux @1.8 1 (sysutils) terminal multiplexer
tmux-pasteboard @2.2 (sysutils) Wrapper to use pasteboard services in tmux
wemux @2.2.0 1 (devel) wemux enhances tmux to make multi-user terminal multiplexing easier and powerful.
Found 4 ports.

4. Install a Specific Package

On you searched for a specific package, you can install it using “install” option as shown below.

When you install a package, it displays all the dependent packages, and install them one by one before installing the given package.

The following will install tmux package. As shown below, it will also install the dependent package “libevent” first, before installing tmux.

$ sudo port install tmux
—> Computing dependencies for tmux
—> Dependencies to be installed: libevent
—> Fetching archive for libevent
—> Installing libevent @2.0.21 0
—> Activating libevent @2.0.21 0
—> Cleaning libevent
—> Fetching archive for tmux
—> Attempting to fetch tmux-1.8 1.darwin 13.x86 64.tbz2 from http://lil.fr.packages.macports.org/tm
—> Attempting to fetch tmux-1.8 1.darwin 13.x86 64.tbz2.rmd160 from http://lil.fr.packages.macport
—> Installing tmux @1.8 1
—> Activating tmux @1.8 1
—> Cleaning tmux
—> Updating database of binaries: 100.0
—> Scanning binaries for linking errors: 100.0
—> No broken files found.

5. View Dependent Packages

If you just want to view all the dependent packages before installing a package, you can do it using deps option as shown below.

This is also helpful to view the dependencies of a package that is already installed.

The following will display all the dependent packages for tmux. As you see below, tmux is dependent on libevent and ncurses packages.

$ sudo port deps tmux
Full Name: tmux @1.8 1
Library Dependencies: libevent, ncurses

6. Uninstall a Package

To uninstall a package, use the uninstall option as shown below. When you uninstall a package, it will not remove the dependencies, it will uninstall only the given package.

The following will uninstall the htop package.

$ sudo port uninstall htop
—> Deactivating htop @ 0
—> Cleaning htop
—> Uninstalling htop @ 0
—> Cleaning htop

7. Uninstall All Old Packages

You can uninstall all old versions of the packages that are not being used now using the “uninstall inacative” option as shown below. Use the -f option also, which will force uninstall all inactive packages as shown below.

$> sudo port -f uninstall inactive
—> Uninstalling automake @1.14 0
—> Cleaning automake
—> Uninstalling gnuplot @4.6.4 1+aquaterm+luaterm+pangocairo+wxwidgets+x11
—> Cleaning gnuplot
—> Uninstalling gnuplot @4.6.4 2+aquaterm+luaterm+pangocairo+wxwidgets+x11
—> Cleaning gnuplot
—> Uninstalling graphviz @2.34.0 2+pangocairo+x11
—> Cleaning graphviz
—> Uninstalling pango @1.36.1 0+x11
—> Cleaning pango
—> Uninstalling texlive-bin @2013 4+x11
—> Cleaning texlive-bin
—> Uninstalling poppler @0.24.4 0
—> Cleaning poppler

8. Delete Downloads of Installed Packages

When you install a package, it downloads the package and then installs it on your system. Once the package is installed, the downloaded file takes-up unnecessary disk space on your system. So, it is a good idea to delete all these downloaded packages once in a while using the “clean -all installed” option.

The following will delete all downloaded packages that are used during installation, but not required anymore, as they are already installed.

$ sudo port clean –all installed
—> Cleaning 2Pong
—> Cleaning 3proxy
—> Cleaning 4th
—> Cleaning 9e
—> Cleaning 54321
—> Cleaning a2ps
—> Cleaning a2ps-j
—> Cleaning a52dec

9. Delete Downloads of All Packages

Sometimes you might’ve downloaded a package, but not installed it on your system yet. You can delete all downloads irrespective of whether they are already installed or not on your system using “clean -all all” option as shown below.

The following will delete all downloaded packages (both installed and not-installed).

$ sudo port clean –all all
—> Cleaning 2Pong
—> Cleaning 3proxy
—> Cleaning 4th
—> Cleaning 9e
—> Cleaning 54321
—> Cleaning a2ps
—> Cleaning a2ps-j
—> Cleaning a52dec
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Keith January 24, 2014, 1:58 am

    Why not use Homebrew? Is there a reason to use Ports over Homebrew, I’m new to OSX and so I’ve only installed and used Homebrew to install the good stuff such as tmux and some other Linux utilities that I wanted.


  • Tilak Varisetty January 24, 2014, 4:14 am

    Thanks for the useful stuff. But the command for deleting downloaded packages should not include “-” before “all”. It should be sudo port clean all installed and
    sudo port clean –all all

  • Rajan Venkataguru January 31, 2014, 9:53 am

    I agree with Keith. Homebrew is a much better and well maintained package manager when compared to port.

  • Sanjay Kumar August 7, 2014, 4:06 am

    @Keith and Rajan: It’s individual person choice which utility or command they want to use for package manager. I started using it because it was supported by OSX developer and In private network, HomeBrew doesn’t work behind proxy.

    @Tilak: Yes, you are right, that is my mistake, i will be more careful in future before writing. It was my first article, so thanks for comments.

  • Jackson Isaac May 13, 2015, 3:51 am


    Good write up. I do agree that it is upto the user’s need. I was using both brew as well as macports, until recently I completely started using macports only.

    From a lot of discussions and hands on experience, I found out that MP installs in /opt/local which will not interfere with any other package. And MP installs all the required dependencies for a port and uses all the packages under /opt/local only and do not depend on Apple provided packages (as they can be old/ broken sometimes) whereas brew doesn’t. brew installs everything under /usr/local (you can change this, but they say “do it at your own peril!”), which was used by MP in the beginning but was changed as it found out that it could interfere with other packages being installed there. Brew can mess up things with other applications installing their packages under /usr/local (eg. Tex, Github, etc) through their DMG.

    P.S: You need to use them all before you actually choose the one that suits you. And I would prefer sticking to one package manager in the end. Also you are always welcome to write ports for missing packages in MP 🙂

    Brew does provides a lot of formulas, but these packages can be built from source too. I do agree that brew would seem to be a easy option for a beginner, but it might mess up your system if you do not know what you are doing.