Original address: http://www.cnblogs.com/ifantastic/p/3677066.html
What is MacPorts?
MacPorts is a third-party package management tool used in Mac OS.
MacPorts allows you to easily compile, install, and manage open source software. MacPorts can be divided into two core parts:
1. Macport Base
2. MacPorts ports.
Each macports Port is a portfile that defines what the application is, its characteristics, and the files and instructions required to install it. With Portfile, you can download, compile, and install applications and library files with just one command. There are some other benefits to managing open source software through MacPorts. For example:
1. Automatically installs all dependent packages for the specified port.
2. Provides uninstall and upgrade functionality for the installed port.
3. Limit all ports to a sandbox so that it does not affect the operating system and is not easy to crash.
4. Allows you to precompile the binary installation package for port so that you can quickly install the package elsewhere without recompiling its source code.
MacPorts was developed on Mac OS X, but it is portable and can be used in other Unix-like systems, especially BSD and its branching versions.
How do I install MacPorts?
1. First install Xcode.
Xcode is a development package from Apple that contains compilers, code libraries, and other tools for developing Mac OS x applications.
You can download Xcode from the Mac APP store or Apple Developer website, or you can search for related resources online. (Click here to download XCode 5.1.dmg)
Note: Make sure that your Mac OS x version is installed and that it matches the latest Xcode, and that using an outdated version will cause the port installation to fail. It is also important to note that prior to OS 10.6, Xcode was not upgraded via Mac OS X's software Update utility, which was upgraded via the Mac APP store after Mac OS X 10.7.
2. Install the macports.
If you're using Mac OS X, you'd better use Mac OS X Package installer to install MacPorts unless you don't want to install MacPorts to its default directory (/opt/local/).
2.1. Mac OS X Package Installer
Mac OS X Package Installer can automatically install MacPorts, set up shell environment, and run the selfupdate command to update ports tree and MacPorts base.
You can download the latest macports Installer from macports download directory. Here are a few download links for the OS X version:
A. OS X 10.7 lion:macports-2.2.1-10.7-lion.pkg
B. OS X 10.8 Mountain lion:macports-2.2.0-10.8-mountainlion.pkg
c. OS X 10.9 mavericks:macports-2.2.1-10.9-mavericks.pkg
10.10 of MacPorts can be downloaded on the website
Once the download is complete, simply double-click the package installer to perform a default installation, and after installation, open a new terminal and execute:
$ Port versionversion:2.2.1
If the installation succeeds, you can see the version number, and if command not found appears, you can try to find the cause here (MacPorts and the Shell).
3. Use MacPorts.
The MacPorts Port command is the primary means of interacting with macports. It is used to update portfiles, macports base parts, install and manage ports.
3.1. Help-command. If the action name is given, a brief description of the operation is displayed, and if the operation name is not given, a basic description of how the Port command is used is displayed.
View Code
3.2. SelfUpdate -This action is used to update the MacPorts, which should be performed frequently to synchronize the local ports tree with the global macports ports warehouse so that you maintain the latest port version. It also checks MacPorts base and updates it in a timely manner.
Note: The SelfUpdate operation applies only to Mac OS X. If you are running MacPorts on another platform, you will need to update the ports tree with the sync operation to install the latest marports to update the current marports base.
$ sudo port selfupdate-updates the current ports tree and MacPorts base.
$ sudo port-d selfupdate-debug mode update, the update details are displayed.
3.3. Sync-Synchronizes ports tree, but does not check macports base.
3.4. List -Lists the current active version of the given ports, and if ports is not given, all valid ports are listed. Because the list is long, if you know a port name, it's a good idea to use the search operation.
xaviermavericks:~ xavier$ Port listapphack @1.1 aqua/apphack...xaviermavericks:~ xavier$ Port list Zope-zsyncerzope-zsyncer @0.6.1 zope/zope-zsyncer
3.5. Search-This action searches for results that match the given name or description.
3.6. Info -Get port Details: Description, maintainer, etc.
3.7. Deps -Displays the port's dependent packages, which need to be explicitly listed in the Portfile.
xaviermavericks:~ xavier$ Port deps apache2full name:apache2 @2.2.26_0+preforkmpmlibrary dependencies:apr, Apr-util, ex Pat, OpenSSL, Pcre, PERL5, zlib
3.8. Variants -This allows you to check the different variants of a port before installing it. Variants is the author of the port that provides some parameters for MacPorts to use during the installation process.
xaviermavericks:~ xavier$ Port variants Nmapnmap have the variants: No_pcre:build without pcre support No_ssl:bui LD without SSL support Universal:build for multiple architectures Zenmap:build zenmap in addition to Nmap
3.9. Install-installs port, if the port has variants, you can install it by adding variants or by removing the default variants.
Normal installation $ sudo port install Nmap Add variant install $ sudo port install Nmap +no_ssl Remove variant install $ sudo port install Fetchmail-ssl
3.10. Clean-cleanup operation to remove macports temporary files that are generated when a port is build. It is also often used to clean up crashed files after a failed fetch operation.
sudo port clean--all vile
3.11. Uninstall -Uninstall operation, uninstall port.
Note: To recursively delete the development package that port depends on, use the--follow-dependencies tag. If the development package has other development packages that depend on it, it will not be deleted.
$ sudo port uninstall--follow-dependencies vile
To remove all development packages that depend on it before deleting the current port, use--follow-dependents.
$ sudo port uninstall--follow-dependents ncurses
If you want to delete a port, but this port is the object that other ports depend on, then MacPorts will not delete it unless you first delete the development package that depends on the package. You can use the-f parameter to force a delete. But use caution unless you are really sure what you are doing.
3.12. Contents -content operation that displays files installed by a port.
3.13. Installed -Lists installed ports. Displays the installed version, Variant, and activation status. Use the-v parameter to show which platform the port is build under which CPU structure.
xaviermavericks:~ xavier$ port-v installed python27the following ports is currently installed: python27 @2.7.6_0 (ac tive) platform= ' Darwin ' archs= ' x86_64 '
3.14. Outdated -lists expired ports. SelfUpdate or sync before using this operation in order to compare whether the currently installed port is the latest version.
3.15. Upgrade -Update operation. When an portfile occurs, use this command to update its corresponding port and its dependent package. If you only want to update port and do not want to update its dependencies, then you can use the-n parameter, but remember, this often happens with a failure.
Normal update $ sudo port upgrade Gnome only updates port, not more its dependent package $ sudo port-n upgrade gnome update all expired port$ sudo port upgrade outdated
Upgrade the default update behavior is to download a new version and enable it, but the old version is not deleted. If you want to update the new version while uninstalling the old version, use the-u parameter.
$ sudo port-u upgrade vile
3.16. Dependents -Lists all development packages that rely on this package.
xaviermavericks:~ xavier$ Port dependents Python27nodejs depends on Python27py27-pip depends on Python27py27-setuptools D Epends on Python27
3.17. Livecheck -Check the remote repository for updates to the port.
3.18. Lint -Check if the portfile conforms to the specification.
xaviermavericks:~ xavier$ Port Lint python27---> verifying portfile for python27---> 0 errors and 0 warning s found.
3.19. Select-in the specified grouping, select a default version and create a link. For example, Python may be linked to Python 2.6. The available select groupings are installed in ${prefix}/etc/select/subdirectories and all groupings are listed using the--summary parameter. To list the available versions in the group, use--list. View the version of the current group selection, using--show. To change the version selected in the grouping, use--set.
Port Select--summaryport Select--show pythonport Select--list pythonport select--set python python34
(go) [OSX] Install the MacPorts guide in OS X