1. Introduction
2. Installing MacPorts
2.1. Install X11
2.2. Install Xcode
2.3. Install MacPorts
2.4. MacPorts Upgrade
2.5. Uninstall
2.6. MacPorts and the Shell
3. Using MacPorts
3.1. The port Command
3.2. Port Variants
3.3. Common Tasks
3.4. Port Binaries
4. Portfile Development
4.1. Portfile Introduction
4.2. Creating a Portfile
4.3. Example Portfiles
4.4. Port Variants
4.5. Patch Files
4.6. Local Portfile Repositories
4.7. Portfile Best Practices
5. Portfile Reference
5.1. Global Keywords
5.2. Global Variables
5.3. Port Phases
5.4. Dependencies
5.5. Variants
5.6. Tcl Extensions
5.7. StartupItems
5.8. Livecheck / Distcheck
5.9. PortGroups
6. MacPorts Internals
6.1. File Hierarchy
6.2. Configuration Files
6.3. Port Images
6.4. APIs and Libs
6.5. The MacPorts Registry
7. MacPorts Project
7.1. Using Trac for tickets
7.2. Contributing to MacPorts
7.3. Port Update Policies
7.4. MacPorts Membership
7.5. The PortMgr Team
8. MacPorts Guide Terms
Glossary
Single Page Chunked

This section lists common operations you may want to perform when managing a MacPorts installation. Some commands are described in further details elsewhere in the guide.

Mind the 'sudo' for some of the subsequent examples, which is necessary if you have a root-MacPorts-installation.

is essential to stay up-to-date with MacPorts:

%% sudo port selfupdate
Password:
--->  Updating the ports tree
--->  Updating MacPorts base sources using rsync
MacPorts base version 1.9.1 installed,
MacPorts base version 1.9.1 downloaded.
--->  MacPorts base is already the latest version

The ports tree has been updated. To upgrade your installed ports, you should run
  port upgrade outdated

is often useful, in case you don't have time to wait for port upgrades (Every port needs to be downloaded, configured, built and installed, which can be - depending on your systems resources - a very time consuming procedure.):

%% port outdated
The following installed ports are outdated:
makedepend                     1.0.2_0 < 1.0.3_0         
Xft2                           2.1.14_0 < 2.2.0_0        
xorg-bigreqsproto              1.1.0_0 < 1.1.1_0         
xorg-compositeproto            0.4.1_0 < 0.4.2_0         
xorg-damageproto               1.2.0_0 < 1.2.1_0         
xorg-fixesproto                4.1.1_0 < 4.1.2_0         
xorg-libXdmcp                  1.0.3_0 < 1.1.0_0         
xorg-libXmu                    1.0.5_0 < 1.1.0_0         
xorg-libXScrnSaver             1.2.0_0 < 1.2.1_0         
xorg-randrproto                1.3.1_0 < 1.3.2_0         
xorg-scrnsaverproto            1.2.0_0 < 1.2.1_0         
xorg-xcmiscproto               1.2.0_0 < 1.2.1_0         
xpm                            3.5.8_0 < 3.5.9_0         
xorg-util-macros               1.10.1_0 < 1.11.0_0

is usually done with the following command:

%% sudo port upgrade outdated

In case you want to upgrade only a specific port (for whatever reason):

%% sudo port upgrade makedepend
Password:
--->  Computing dependencies for makedepend
--->  Fetching makedepend
--->  Attempting to fetch makedepend-1.0.3.tar.bz2 from http://lil.fr.distfiles.macports.org/makedepend
--->  Verifying checksum(s) for makedepend
--->  Extracting makedepend
--->  Configuring makedepend
--->  Building makedepend
--->  Staging makedepend into destroot
--->  Computing dependencies for makedepend
--->  Installing makedepend @1.0.3_0
--->  Deactivating makedepend @1.0.2_0
--->  Activating makedepend @1.0.3_0
--->  Cleaning makedepend

makes sense if you are sure that you won't change back to the older version(s) (which could be necessary in case of newly introduced bugs in the upgraded port version):

%% port installed inactive
The following ports are currently installed:
  makedepend @1.0.2_0
%% sudo port uninstall inactive
Password:
--->  Uninstalling makedepend @1.0.2_0

Of course one could also select only a specific inactive port, but that requires to specify the exact version:

%% sudo port uninstall makedepend @1.0.2_0
Password:
--->  Uninstalling makedepend @1.0.2_0

can sometimes be very helpful (example: find ports depending on 'xorg-util-macros'):

%% port echo depends:xorg-util-macros
mkfontscale
xorg-libAppleWM
xorg-libX11
xorg-libXaw
xorg-libXevie
xorg-libXp
xorg-libXt
xorg-server
xorg-server-devel
xscope
xtrap

can be sometimes worthwhile, since often additional ports get installed when a specific port is installed. One can imagine that if one keeps installing and uninstalling ports for some time the MacPorts tree can be swamped with ports actually not necessary anymore. Leaves can be found by issuing the command:

%% port echo leaves
aalib                          @1.4rc5_4 
autoconf                       @2.68_0 
autoconf263                    @2.63_0 
automake                       @1.11.1_0 
cmake                          @2.8.2_4 
coreutils                      @8.5_0

The following command delivers a similar result:

%% port installed leaves
  aalib @1.4rc5_4 (active)
  autoconf @2.68_0 (active)
  autoconf263 @2.63_0 (active)
  automake @1.11.1_0 (active)
  cmake @2.8.2_4 (active)
  coreutils @8.5_0 (active)

These leaves may be wanted, but could also be unwanted ports. (See the following entry!)

Well, before we come to the procedure of defining your requested ports, let's have a look at a typical scenario where you want to understand what is actually installed and what is on the other hand truly necessary for your system. Say checking leaves of your MacPorts installation gives this output:

%% port echo leaves
aalib                          @1.4rc5_4 
autoconf                       @2.68_0 
autoconf263                    @2.63_0 
automake                       @1.11.1_0 
cmake                          @2.8.2_4 
coreutils                      @8.5_0 
physfs                         @2.0.1_0

Now it is up to the user to decide what's needed and what is not. Let's say one certainly would want ports starting with autoconf up to coreutils, since they are often used in port installation. Set those as requested ports using:

%% sudo port setrequested autoconf autoconf263 automake cmake coreutils

Say port aalib is not needed anymore, while physfs seems odd and since you don't know what to make of it, you need to check out what it actually is and which ports needed its installation at some time in the past.

%% port info physfs
physfs @2.0.1 (devel)
Variants:             debug, universal

Description:          PhysicsFS is a library to provide abstract access to various
                      archives. It is intended for use in video games, and the design
                      was somewhat inspired by Quake 3's file subsystem.
Homepage:             http://icculus.org/physfs/

Build Dependencies:   cmake
Library Dependencies: zlib
Platforms:            darwin
License:              unknown
Maintainers:          nomaintainer@macports.org

Well, hmm, you certainly didn't want to install Quake 3 in the past. So, let's find out which ports actually depend on it, perhaps that might ring a bell:

%% port echo depends:physfs
fbg                             
libsdl_sound                    
lincity-ng                      
netpanzer

No, you didn't install netpanzer either, but - see there - fbg (The classic Falling Block Game!) was once on your agenda. But unfortunately that port was broken (see issue #24641) when you were trying to install it... Before you ran into the issue, of course, fbg's dependencies were resolved by MacPorts, which is why port physfs is still present on your system. Uff, great, confusion resolved. :-)

When you've step-by-step figured out which ports you want to keep on your system and have set them as requested, you'll have a list of unnecessary ports, which might be eventually as short as this:

%% port echo leaves
aalib                          @1.4rc5_4 
physfs                         @2.0.1_0 

Get rid of them by issuing the command:

%% sudo port uninstall leaves
--->  Deactivating physfs @2.0.1_0
--->  Cleaning physfs
--->  Uninstalling physfs @2.0.1_0
--->  Cleaning physfs
--->  Deactivating aalib @1.4rc5_4
--->  Uninstalling aalib @1.4rc5_4

Find all installed ports you previously set as requested using:

%% port installed requested

Checking the list of leaves from time to time will help to keep your system free of too much "garbage". However, keep in mind that some ports may be dependencies only during the installation of a port (library dependencies, installation or configuration tools, etc.). So, be careful when removing seemingly unnecessary leaves, otherwise you'll see them being installed again and again.