Installing MacPortsThis chapter shows you how to install MacPorts and its prerequisites
step-by-step. Note that sections 1 through 3 are Mac OS X specific. If you
wish to install MacPorts on another platform, first make sure you have X11
and gcc installed, and then perform a MacPorts install from source code.Install X11It is recommended that you install the X Window System (X11) even if
you don't plan to run X11 applications immediately. Apple's X11 is
preferred over the MacPorts X11 port, and ports with an X11 dependency
will be satisfied by Apple's X11. If Apple's X11 wasn't installed at the
same time Mac OS X was installed, follow these steps.Insert the "Mac OS X Install Disk" and run the package named
"Optional Installs".At the software selection window expand the Applications
category and click the check box beside X11 (and nothing else).Click Install to install X11.Drag the /Applications/Utilities/X11 icon
to your dock —you must open X11 before launching an X11
application.If you're using Mac OS X 10.3 then you can download the X11 installer
from the Apple download
page.X11 and the X11SDK (from Xcode Tools) are both required for X11
apps. To verify the presence of both, check for files
com.apple.pkg.X11User.bom &
com.apple.pkg.X11SDKLeo.bom in
/Library/Receipts/boms/. On Mac OS X 10.4, look for
files X11User.pkg &
X11SDK.pkg in
/Library/Receipts/.Optional X11 SettingsTo launch X11 applications directly from an X11 window (instead of
a terminal window), you need to have the MacPorts paths imported into
X11 sessions when they are opened. This is a two step process.First, tell X11 about the ~/.profile file
that will be created after you install MacPorts. Do this by editing the
file /etc/X11/xinit/xinitrc and adding this line
near the top.source ~/.profileNow finish the process by making subsequent X11 sessions opened
using the menu bar respect your .profile
file.Open X11 and select "Customize Menu ..." from the Applications
menu.Double-click the menu item "Terminal" and change: "xterm" to
"xterm -ls"Click "Done" to save the change.Install Xcode ToolsTo install Xcode Tools and the X11 SDK, follow these steps.Download and install the latest version of Xcode Tools from
Apple's developer site—do not install it from a Mac OS X install disk
unless you've already checked for a more recent version on Apple's
site; older versions of Xcode Tools often cause port install
failures.Run the Xcode Tools package installer.Click the button Customize, expand the
Applications category and click the check box beside X11
SDK to add it to the default items.Click Install to install Xcode Tools and
the X11 SDK.Xcode Tools are not updated via Mac OS X's Software Update
utility.Install MacPortsIf you are using Mac OS X, you should install MacPorts using the
Mac OS X package installer unless you do not wish to install it to
/opt/local/, the default MacPorts location, or if you
wish to install a pre-release version of MacPorts base. However, if you
wish to install multiple copies of
MacPorts or install MacPorts on another OS platform, you must
install MacPorts from the source
code.Though a distinction is made between pre-release and release
versions of MacPorts base, the ports collection supports no versioning;
a selfupdate installs the
latest commits from subversion (at a slight delay).Mac OS X Package InstallTo install MacPorts with the Mac OS X package installer, follow
these steps.Download the latest MacPorts .dmg disk image from the MacPorts
download directory.Double-click the .pkg package installer on the disk
image.Perform the default “easy” install. As of MacPorts 1.6,
this will install MacPorts, set up a MacPorts-compatible shell
environment and, if you have a network connection, update the
MacPorts core and ports tree.For advanced users: details of the postflight script
The "postflight" script bundled with our "pkg" installer is
run by Apple's Installer.app after MacPorts is installed, in order
to setup a MacPorts-compatible shell environment by editing the appropriate
shell configuration file (which is properly backed up if necessary
with an "mpsaved_$timestamp" suffix before proceeding):
The "/opt/local/bin" & "/opt/local/sbin" paths are
added to the PATH variable if not already there, in order to
find MacPorts-installed programs.The "/opt/local/share/man" path is added to the MANPATH
variable if and only if:
it already exists;its value is not empty;the MacPorts path is not already in it;its value does not contain empty components, such
as "/usr/share/man:", ":/usr/share/man" or
"/usr/share/man::/usr/X11R6/man".
In all of these cases, helper tools such as 'manpath(1)' or
'path_helper(8)' (Leopard only) setup the MANPATH directly in
coordination with the 'man(1)' command, so we avoid
interfering with that.
The DISPLAY environment variable is set
to ":0" if and only if:
It's a Tiger or earlier platform, since on Leopard
connections to the X11 server are handled in a much
cleaner fashion by the 'launchd(8)' daemon directly;
a DISPLAY environment variable doesn't
already exist.
Once all that is done, the script runs the 'selfupdate'
action of the 'port(1)' command to synchronize the MacPorts
installation with the project's rsync server, updating the
ports tree to its latest revision and MacPorts itself to the
latest point release if available.Source InstallIf you installed MacPorts using the package installer, skip this
section. To install MacPorts from the source code, follow these
steps.Download and unzip the latest MacPorts tarball from the MacPorts
download directory.Perform these commands in a terminal window, substituting a
real path for NEW_PREFIX if you wish to use a path other than
/opt/local/.%%cd ~/MacPorts-1.x.x/%%./configure --prefix=NEW_PREFIX (setting prefix is optional)
%%make%%sudo make installInstall Multiple MacPorts CopiesOccasionally a MacPorts developer may wish to install more than
one copy of MacPorts on the same host, possibly to test two different
versions of MacPorts. But only one copy of MacPorts may use the
default MacPorts Tcl library path /Library/Tcl/,
so for a second installation use the
--with-tclpackage switch set to any newly created
(empty) directory, say /Library/Tcl/macports-new. Also, the standard
MacPorts binary path must not be present during the installation of
the second instance. To install a second instance of MacPorts, follow
these steps.%%export PATH=/bin:/sbin:/usr/bin:/usr/sbin%%cd ~/MacPorts-1.x.x/%%./configure --prefix=NEW_PREFIX --with-tcl-package=NEW_TCLPACKAGE%%make%%sudo make installUninstallTo uninstall MacPorts from the default location
/opt/local/, perform these commands from a terminal
window.%%sudo rm -rf /opt/local/%%sudo rm -rf /Applications/MacPorts/%%sudo rm -rf /Library/Tcl/macports1.0/%%sudo rm -rf /Library/LaunchDaemons/org.macports.*Set the Bash ShellThe MacPorts installer (from Mac OS X package or source) places a
.profile file in your home directory (view files with
a dot using ls -a). The contents of the
~/.profile adds the MacPorts paths in front of the
standard Unix paths for the default Bash shell so that MacPorts libraries
will take precedence over vendor-supplied libraries if both are
present.The path statement in the MacPorts-installed .profile is set as
shown.export PATH=/opt/local/bin:/opt/local/sbin:$PATHYou must add this DISPLAY variable for
X11.export DISPLAY=:0.0Add the EDITOR variable to use your favorite text
editor. A complete ~/.profile file with the added
variables is shown below.export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export DISPLAY=:0.0
export EDITOR=/usr/bin/pico
Changes to ~/.profile do not take effect until
a new terminal session is opened. Type env in the
terminal to verify the current environment settings. Example output of
env is below.TERM_PROGRAM=Apple_Terminal
TERM=xterm-color
SHELL=/bin/bash
TERM_PROGRAM_VERSION=133
USER=joebob
__CF_USER_TEXT_ENCODING=0x1FC:0:0
PATH=/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
PWD=/Users/joebob
EDITOR=/usr/bin/pico
SHLVL=1
HOME=/Users/joebob
LOGNAME=joebob
DISPLAY=:0.0
SECURITYSESSIONID=b0cea0
_=/usr/bin/envIf you have either a .bash_login or a
.bash_profile file in your home directory, they may
take precedence over .profile. You may either
remove the previously used file, or add the contents of
.profile to it.Selfupdate MacPortsYou must always execute a selfupdate after a new
MacPorts install, and you should also do it frequently thereafter. See
selfupdate —one of several
port commands.